
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Form fields &#8212; Django 1.11.22.dev20190603194737 documentation</title>
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/language_data.js"></script>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="Model Form Functions" href="models.html" />
    <link rel="prev" title="The Forms API" href="api.html" />



 
<script type="text/javascript" src="../../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);
</script>


  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../index.html">Django 1.11.22.dev20190603194737 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../index.html">Home</a>  |
        <a title="Table of contents" href="../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../genindex.html">Index</a>  |
        <a title="Module index" href="../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="api.html" title="The Forms API">previous</a>
     |
    <a href="../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="models.html" title="Model Form Functions">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-forms-fields">
            
  <div class="section" id="s-module-django.forms.fields">
<span id="s-form-fields"></span><span id="module-django.forms.fields"></span><span id="form-fields"></span><h1>Form fields<a class="headerlink" href="#module-django.forms.fields" title="Permalink to this headline">¶</a></h1>
<dl class="class">
<dt id="django.forms.Field">
<em class="property">class </em><code class="descname">Field</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#Field"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.Field" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>When you create a <code class="docutils literal notranslate"><span class="pre">Form</span></code> class, the most important part is defining the
fields of the form. Each field has custom validation logic, along with a few
other hooks.</p>
<dl class="method">
<dt id="django.forms.Field.clean">
<code class="descclassname">Field.</code><code class="descname">clean</code>(<em>value</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#Field.clean"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.Field.clean" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>Although the primary way you’ll use <code class="docutils literal notranslate"><span class="pre">Field</span></code> classes is in <code class="docutils literal notranslate"><span class="pre">Form</span></code> classes,
you can also instantiate them and use them directly to get a better idea of
how they work. Each <code class="docutils literal notranslate"><span class="pre">Field</span></code> instance has a <code class="docutils literal notranslate"><span class="pre">clean()</span></code> method, which takes
a single argument and either raises a <code class="docutils literal notranslate"><span class="pre">django.forms.ValidationError</span></code>
exception or returns the clean value:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">django</span> <span class="k">import</span> <span class="n">forms</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">EmailField</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">clean</span><span class="p">(</span><span class="s1">&#39;foo@example.com&#39;</span><span class="p">)</span>
<span class="go">&#39;foo@example.com&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">clean</span><span class="p">(</span><span class="s1">&#39;invalid email address&#39;</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">ValidationError</span>: <span class="n">[&#39;Enter a valid email address.&#39;]</span>
</pre></div>
</div>
<div class="section" id="s-core-field-arguments">
<span id="s-id1"></span><span id="core-field-arguments"></span><span id="id1"></span><h2>Core field arguments<a class="headerlink" href="#core-field-arguments" title="Permalink to this headline">¶</a></h2>
<p>Each <code class="docutils literal notranslate"><span class="pre">Field</span></code> class constructor takes at least these arguments. Some
<code class="docutils literal notranslate"><span class="pre">Field</span></code> classes take additional, field-specific arguments, but the following
should <em>always</em> be accepted:</p>
<div class="section" id="s-required">
<span id="required"></span><h3><code class="docutils literal notranslate"><span class="pre">required</span></code><a class="headerlink" href="#required" title="Permalink to this headline">¶</a></h3>
<dl class="attribute">
<dt id="django.forms.Field.required">
<code class="descclassname">Field.</code><code class="descname">required</code><a class="headerlink" href="#django.forms.Field.required" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>By default, each <code class="docutils literal notranslate"><span class="pre">Field</span></code> class assumes the value is required, so if you pass
an empty value – either <code class="docutils literal notranslate"><span class="pre">None</span></code> or the empty string (<code class="docutils literal notranslate"><span class="pre">&quot;&quot;</span></code>) – then
<code class="docutils literal notranslate"><span class="pre">clean()</span></code> will raise a <code class="docutils literal notranslate"><span class="pre">ValidationError</span></code> exception:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">django</span> <span class="k">import</span> <span class="n">forms</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">clean</span><span class="p">(</span><span class="s1">&#39;foo&#39;</span><span class="p">)</span>
<span class="go">&#39;foo&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">clean</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">ValidationError</span>: <span class="n">[&#39;This field is required.&#39;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">clean</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">ValidationError</span>: <span class="n">[&#39;This field is required.&#39;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">clean</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="p">)</span>
<span class="go">&#39; &#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">clean</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="go">&#39;0&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">clean</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
<span class="go">&#39;True&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">clean</span><span class="p">(</span><span class="kc">False</span><span class="p">)</span>
<span class="go">&#39;False&#39;</span>
</pre></div>
</div>
<p>To specify that a field is <em>not</em> required, pass <code class="docutils literal notranslate"><span class="pre">required=False</span></code> to the
<code class="docutils literal notranslate"><span class="pre">Field</span></code> constructor:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">required</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">clean</span><span class="p">(</span><span class="s1">&#39;foo&#39;</span><span class="p">)</span>
<span class="go">&#39;foo&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">clean</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">)</span>
<span class="go">&#39;&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">clean</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span>
<span class="go">&#39;&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">clean</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="go">&#39;0&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">clean</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
<span class="go">&#39;True&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">clean</span><span class="p">(</span><span class="kc">False</span><span class="p">)</span>
<span class="go">&#39;False&#39;</span>
</pre></div>
</div>
<p>If a <code class="docutils literal notranslate"><span class="pre">Field</span></code> has <code class="docutils literal notranslate"><span class="pre">required=False</span></code> and you pass <code class="docutils literal notranslate"><span class="pre">clean()</span></code> an empty value,
then <code class="docutils literal notranslate"><span class="pre">clean()</span></code> will return a <em>normalized</em> empty value rather than raising
<code class="docutils literal notranslate"><span class="pre">ValidationError</span></code>. For <code class="docutils literal notranslate"><span class="pre">CharField</span></code>, this will be a Unicode empty string.
For other <code class="docutils literal notranslate"><span class="pre">Field</span></code> classes, it might be <code class="docutils literal notranslate"><span class="pre">None</span></code>. (This varies from field to
field.)</p>
<p>Widgets of required form fields have the <code class="docutils literal notranslate"><span class="pre">required</span></code> HTML attribute. Set the
<a class="reference internal" href="api.html#django.forms.Form.use_required_attribute" title="django.forms.Form.use_required_attribute"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Form.use_required_attribute</span></code></a> attribute to <code class="docutils literal notranslate"><span class="pre">False</span></code> to disable it. The
<code class="docutils literal notranslate"><span class="pre">required</span></code> attribute isn’t included on forms of formsets because the browser
validation may not be correct when adding and deleting formsets.</p>
<div class="versionadded">
<span class="title">New in Django 1.10:</span> <p>Support for the <code class="docutils literal notranslate"><span class="pre">required</span></code> HTML attribute was added.</p>
</div>
</div>
<div class="section" id="s-label">
<span id="label"></span><h3><code class="docutils literal notranslate"><span class="pre">label</span></code><a class="headerlink" href="#label" title="Permalink to this headline">¶</a></h3>
<dl class="attribute">
<dt id="django.forms.Field.label">
<code class="descclassname">Field.</code><code class="descname">label</code><a class="headerlink" href="#django.forms.Field.label" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>The <code class="docutils literal notranslate"><span class="pre">label</span></code> argument lets you specify the “human-friendly” label for this
field. This is used when the <code class="docutils literal notranslate"><span class="pre">Field</span></code> is displayed in a <code class="docutils literal notranslate"><span class="pre">Form</span></code>.</p>
<p>As explained in “Outputting forms as HTML” above, the default label for a
<code class="docutils literal notranslate"><span class="pre">Field</span></code> is generated from the field name by converting all underscores to
spaces and upper-casing the first letter. Specify <code class="docutils literal notranslate"><span class="pre">label</span></code> if that default
behavior doesn’t result in an adequate label.</p>
<p>Here’s a full example <code class="docutils literal notranslate"><span class="pre">Form</span></code> that implements <code class="docutils literal notranslate"><span class="pre">label</span></code> for two of its fields.
We’ve specified <code class="docutils literal notranslate"><span class="pre">auto_id=False</span></code> to simplify the output:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">django</span> <span class="k">import</span> <span class="n">forms</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">CommentForm</span><span class="p">(</span><span class="n">forms</span><span class="o">.</span><span class="n">Form</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">name</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">label</span><span class="o">=</span><span class="s1">&#39;Your name&#39;</span><span class="p">)</span>
<span class="gp">... </span>    <span class="n">url</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">URLField</span><span class="p">(</span><span class="n">label</span><span class="o">=</span><span class="s1">&#39;Your website&#39;</span><span class="p">,</span> <span class="n">required</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">... </span>    <span class="n">comment</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">CommentForm</span><span class="p">(</span><span class="n">auto_id</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
<span class="go">&lt;tr&gt;&lt;th&gt;Your name:&lt;/th&gt;&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;name&quot; required /&gt;&lt;/td&gt;&lt;/tr&gt;</span>
<span class="go">&lt;tr&gt;&lt;th&gt;Your website:&lt;/th&gt;&lt;td&gt;&lt;input type=&quot;url&quot; name=&quot;url&quot; /&gt;&lt;/td&gt;&lt;/tr&gt;</span>
<span class="go">&lt;tr&gt;&lt;th&gt;Comment:&lt;/th&gt;&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;comment&quot; required /&gt;&lt;/td&gt;&lt;/tr&gt;</span>
</pre></div>
</div>
</div>
<div class="section" id="s-label-suffix">
<span id="label-suffix"></span><h3><code class="docutils literal notranslate"><span class="pre">label_suffix</span></code><a class="headerlink" href="#label-suffix" title="Permalink to this headline">¶</a></h3>
<dl class="attribute">
<dt id="django.forms.Field.label_suffix">
<code class="descclassname">Field.</code><code class="descname">label_suffix</code><a class="headerlink" href="#django.forms.Field.label_suffix" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>The <code class="docutils literal notranslate"><span class="pre">label_suffix</span></code> argument lets you override the form’s
<a class="reference internal" href="api.html#django.forms.Form.label_suffix" title="django.forms.Form.label_suffix"><code class="xref py py-attr docutils literal notranslate"><span class="pre">label_suffix</span></code></a> on a per-field basis:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">ContactForm</span><span class="p">(</span><span class="n">forms</span><span class="o">.</span><span class="n">Form</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">age</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">IntegerField</span><span class="p">()</span>
<span class="gp">... </span>    <span class="n">nationality</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">()</span>
<span class="gp">... </span>    <span class="n">captcha_answer</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">IntegerField</span><span class="p">(</span><span class="n">label</span><span class="o">=</span><span class="s1">&#39;2 + 2&#39;</span><span class="p">,</span> <span class="n">label_suffix</span><span class="o">=</span><span class="s1">&#39; =&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">ContactForm</span><span class="p">(</span><span class="n">label_suffix</span><span class="o">=</span><span class="s1">&#39;?&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">as_p</span><span class="p">())</span>
<span class="go">&lt;p&gt;&lt;label for=&quot;id_age&quot;&gt;Age?&lt;/label&gt; &lt;input id=&quot;id_age&quot; name=&quot;age&quot; type=&quot;number&quot; required /&gt;&lt;/p&gt;</span>
<span class="go">&lt;p&gt;&lt;label for=&quot;id_nationality&quot;&gt;Nationality?&lt;/label&gt; &lt;input id=&quot;id_nationality&quot; name=&quot;nationality&quot; type=&quot;text&quot; required /&gt;&lt;/p&gt;</span>
<span class="go">&lt;p&gt;&lt;label for=&quot;id_captcha_answer&quot;&gt;2 + 2 =&lt;/label&gt; &lt;input id=&quot;id_captcha_answer&quot; name=&quot;captcha_answer&quot; type=&quot;number&quot; required /&gt;&lt;/p&gt;</span>
</pre></div>
</div>
</div>
<div class="section" id="s-initial">
<span id="initial"></span><h3><code class="docutils literal notranslate"><span class="pre">initial</span></code><a class="headerlink" href="#initial" title="Permalink to this headline">¶</a></h3>
<dl class="attribute">
<dt id="django.forms.Field.initial">
<code class="descclassname">Field.</code><code class="descname">initial</code><a class="headerlink" href="#django.forms.Field.initial" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>The <code class="docutils literal notranslate"><span class="pre">initial</span></code> argument lets you specify the initial value to use when
rendering this <code class="docutils literal notranslate"><span class="pre">Field</span></code> in an unbound <code class="docutils literal notranslate"><span class="pre">Form</span></code>.</p>
<p>To specify dynamic initial data, see the <a class="reference internal" href="api.html#django.forms.Form.initial" title="django.forms.Form.initial"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Form.initial</span></code></a> parameter.</p>
<p>The use-case for this is when you want to display an “empty” form in which a
field is initialized to a particular value. For example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">django</span> <span class="k">import</span> <span class="n">forms</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">CommentForm</span><span class="p">(</span><span class="n">forms</span><span class="o">.</span><span class="n">Form</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">name</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">initial</span><span class="o">=</span><span class="s1">&#39;Your name&#39;</span><span class="p">)</span>
<span class="gp">... </span>    <span class="n">url</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">URLField</span><span class="p">(</span><span class="n">initial</span><span class="o">=</span><span class="s1">&#39;http://&#39;</span><span class="p">)</span>
<span class="gp">... </span>    <span class="n">comment</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">CommentForm</span><span class="p">(</span><span class="n">auto_id</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
<span class="go">&lt;tr&gt;&lt;th&gt;Name:&lt;/th&gt;&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;name&quot; value=&quot;Your name&quot; required /&gt;&lt;/td&gt;&lt;/tr&gt;</span>
<span class="go">&lt;tr&gt;&lt;th&gt;Url:&lt;/th&gt;&lt;td&gt;&lt;input type=&quot;url&quot; name=&quot;url&quot; value=&quot;http://&quot; required /&gt;&lt;/td&gt;&lt;/tr&gt;</span>
<span class="go">&lt;tr&gt;&lt;th&gt;Comment:&lt;/th&gt;&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;comment&quot; required /&gt;&lt;/td&gt;&lt;/tr&gt;</span>
</pre></div>
</div>
<p>You may be thinking, why not just pass a dictionary of the initial values as
data when displaying the form? Well, if you do that, you’ll trigger validation,
and the HTML output will include any validation errors:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">CommentForm</span><span class="p">(</span><span class="n">forms</span><span class="o">.</span><span class="n">Form</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">name</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">()</span>
<span class="gp">... </span>    <span class="n">url</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">URLField</span><span class="p">()</span>
<span class="gp">... </span>    <span class="n">comment</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">default_data</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;name&#39;</span><span class="p">:</span> <span class="s1">&#39;Your name&#39;</span><span class="p">,</span> <span class="s1">&#39;url&#39;</span><span class="p">:</span> <span class="s1">&#39;http://&#39;</span><span class="p">}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">CommentForm</span><span class="p">(</span><span class="n">default_data</span><span class="p">,</span> <span class="n">auto_id</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
<span class="go">&lt;tr&gt;&lt;th&gt;Name:&lt;/th&gt;&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;name&quot; value=&quot;Your name&quot; required /&gt;&lt;/td&gt;&lt;/tr&gt;</span>
<span class="go">&lt;tr&gt;&lt;th&gt;Url:&lt;/th&gt;&lt;td&gt;&lt;ul class=&quot;errorlist&quot;&gt;&lt;li&gt;Enter a valid URL.&lt;/li&gt;&lt;/ul&gt;&lt;input type=&quot;url&quot; name=&quot;url&quot; value=&quot;http://&quot; required /&gt;&lt;/td&gt;&lt;/tr&gt;</span>
<span class="go">&lt;tr&gt;&lt;th&gt;Comment:&lt;/th&gt;&lt;td&gt;&lt;ul class=&quot;errorlist&quot;&gt;&lt;li&gt;This field is required.&lt;/li&gt;&lt;/ul&gt;&lt;input type=&quot;text&quot; name=&quot;comment&quot; required /&gt;&lt;/td&gt;&lt;/tr&gt;</span>
</pre></div>
</div>
<p>This is why <code class="docutils literal notranslate"><span class="pre">initial</span></code> values are only displayed for unbound forms. For bound
forms, the HTML output will use the bound data.</p>
<p>Also note that <code class="docutils literal notranslate"><span class="pre">initial</span></code> values are <em>not</em> used as “fallback” data in
validation if a particular field’s value is not given. <code class="docutils literal notranslate"><span class="pre">initial</span></code> values are
<em>only</em> intended for initial form display:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">CommentForm</span><span class="p">(</span><span class="n">forms</span><span class="o">.</span><span class="n">Form</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">name</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">initial</span><span class="o">=</span><span class="s1">&#39;Your name&#39;</span><span class="p">)</span>
<span class="gp">... </span>    <span class="n">url</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">URLField</span><span class="p">(</span><span class="n">initial</span><span class="o">=</span><span class="s1">&#39;http://&#39;</span><span class="p">)</span>
<span class="gp">... </span>    <span class="n">comment</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;name&#39;</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="s1">&#39;url&#39;</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="s1">&#39;comment&#39;</span><span class="p">:</span> <span class="s1">&#39;Foo&#39;</span><span class="p">}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">CommentForm</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">is_valid</span><span class="p">()</span>
<span class="go">False</span>
<span class="go"># The form does *not* fall back to using the initial values.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">errors</span>
<span class="go">{&#39;url&#39;: [&#39;This field is required.&#39;], &#39;name&#39;: [&#39;This field is required.&#39;]}</span>
</pre></div>
</div>
<p>Instead of a constant, you can also pass any callable:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">datetime</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">DateForm</span><span class="p">(</span><span class="n">forms</span><span class="o">.</span><span class="n">Form</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">day</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">DateField</span><span class="p">(</span><span class="n">initial</span><span class="o">=</span><span class="n">datetime</span><span class="o">.</span><span class="n">date</span><span class="o">.</span><span class="n">today</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">DateForm</span><span class="p">())</span>
<span class="go">&lt;tr&gt;&lt;th&gt;Day:&lt;/th&gt;&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;day&quot; value=&quot;12/23/2008&quot; required /&gt;&lt;td&gt;&lt;/tr&gt;</span>
</pre></div>
</div>
<p>The callable will be evaluated only when the unbound form is displayed, not when it is defined.</p>
</div>
<div class="section" id="s-widget">
<span id="widget"></span><h3><code class="docutils literal notranslate"><span class="pre">widget</span></code><a class="headerlink" href="#widget" title="Permalink to this headline">¶</a></h3>
<dl class="attribute">
<dt id="django.forms.Field.widget">
<code class="descclassname">Field.</code><code class="descname">widget</code><a class="headerlink" href="#django.forms.Field.widget" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>The <code class="docutils literal notranslate"><span class="pre">widget</span></code> argument lets you specify a <code class="docutils literal notranslate"><span class="pre">Widget</span></code> class to use when
rendering this <code class="docutils literal notranslate"><span class="pre">Field</span></code>. See <a class="reference internal" href="widgets.html"><span class="doc">Widgets</span></a> for more information.</p>
</div>
<div class="section" id="s-help-text">
<span id="help-text"></span><h3><code class="docutils literal notranslate"><span class="pre">help_text</span></code><a class="headerlink" href="#help-text" title="Permalink to this headline">¶</a></h3>
<dl class="attribute">
<dt id="django.forms.Field.help_text">
<code class="descclassname">Field.</code><code class="descname">help_text</code><a class="headerlink" href="#django.forms.Field.help_text" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>The <code class="docutils literal notranslate"><span class="pre">help_text</span></code> argument lets you specify descriptive text for this
<code class="docutils literal notranslate"><span class="pre">Field</span></code>. If you provide <code class="docutils literal notranslate"><span class="pre">help_text</span></code>, it will be displayed next to the
<code class="docutils literal notranslate"><span class="pre">Field</span></code> when the <code class="docutils literal notranslate"><span class="pre">Field</span></code> is rendered by one of the convenience <code class="docutils literal notranslate"><span class="pre">Form</span></code>
methods (e.g., <code class="docutils literal notranslate"><span class="pre">as_ul()</span></code>).</p>
<p>Like the model field’s <a class="reference internal" href="../models/fields.html#django.db.models.Field.help_text" title="django.db.models.Field.help_text"><code class="xref py py-attr docutils literal notranslate"><span class="pre">help_text</span></code></a>, this value
isn’t HTML-escaped in automatically-generated forms.</p>
<p>Here’s a full example <code class="docutils literal notranslate"><span class="pre">Form</span></code> that implements <code class="docutils literal notranslate"><span class="pre">help_text</span></code> for two of its
fields. We’ve specified <code class="docutils literal notranslate"><span class="pre">auto_id=False</span></code> to simplify the output:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">django</span> <span class="k">import</span> <span class="n">forms</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">HelpTextContactForm</span><span class="p">(</span><span class="n">forms</span><span class="o">.</span><span class="n">Form</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">subject</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span> <span class="n">help_text</span><span class="o">=</span><span class="s1">&#39;100 characters max.&#39;</span><span class="p">)</span>
<span class="gp">... </span>    <span class="n">message</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">()</span>
<span class="gp">... </span>    <span class="n">sender</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">EmailField</span><span class="p">(</span><span class="n">help_text</span><span class="o">=</span><span class="s1">&#39;A valid email address, please.&#39;</span><span class="p">)</span>
<span class="gp">... </span>    <span class="n">cc_myself</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">BooleanField</span><span class="p">(</span><span class="n">required</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">HelpTextContactForm</span><span class="p">(</span><span class="n">auto_id</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">as_table</span><span class="p">())</span>
<span class="go">&lt;tr&gt;&lt;th&gt;Subject:&lt;/th&gt;&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;subject&quot; maxlength=&quot;100&quot; required /&gt;&lt;br /&gt;&lt;span class=&quot;helptext&quot;&gt;100 characters max.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;</span>
<span class="go">&lt;tr&gt;&lt;th&gt;Message:&lt;/th&gt;&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;message&quot; required /&gt;&lt;/td&gt;&lt;/tr&gt;</span>
<span class="go">&lt;tr&gt;&lt;th&gt;Sender:&lt;/th&gt;&lt;td&gt;&lt;input type=&quot;email&quot; name=&quot;sender&quot; required /&gt;&lt;br /&gt;A valid email address, please.&lt;/td&gt;&lt;/tr&gt;</span>
<span class="go">&lt;tr&gt;&lt;th&gt;Cc myself:&lt;/th&gt;&lt;td&gt;&lt;input type=&quot;checkbox&quot; name=&quot;cc_myself&quot; /&gt;&lt;/td&gt;&lt;/tr&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">as_ul</span><span class="p">()))</span>
<span class="go">&lt;li&gt;Subject: &lt;input type=&quot;text&quot; name=&quot;subject&quot; maxlength=&quot;100&quot; required /&gt; &lt;span class=&quot;helptext&quot;&gt;100 characters max.&lt;/span&gt;&lt;/li&gt;</span>
<span class="go">&lt;li&gt;Message: &lt;input type=&quot;text&quot; name=&quot;message&quot; required /&gt;&lt;/li&gt;</span>
<span class="go">&lt;li&gt;Sender: &lt;input type=&quot;email&quot; name=&quot;sender&quot; required /&gt; A valid email address, please.&lt;/li&gt;</span>
<span class="go">&lt;li&gt;Cc myself: &lt;input type=&quot;checkbox&quot; name=&quot;cc_myself&quot; /&gt;&lt;/li&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">as_p</span><span class="p">())</span>
<span class="go">&lt;p&gt;Subject: &lt;input type=&quot;text&quot; name=&quot;subject&quot; maxlength=&quot;100&quot; required /&gt; &lt;span class=&quot;helptext&quot;&gt;100 characters max.&lt;/span&gt;&lt;/p&gt;</span>
<span class="go">&lt;p&gt;Message: &lt;input type=&quot;text&quot; name=&quot;message&quot; required /&gt;&lt;/p&gt;</span>
<span class="go">&lt;p&gt;Sender: &lt;input type=&quot;email&quot; name=&quot;sender&quot; required /&gt; A valid email address, please.&lt;/p&gt;</span>
<span class="go">&lt;p&gt;Cc myself: &lt;input type=&quot;checkbox&quot; name=&quot;cc_myself&quot; /&gt;&lt;/p&gt;</span>
</pre></div>
</div>
</div>
<div class="section" id="s-error-messages">
<span id="error-messages"></span><h3><code class="docutils literal notranslate"><span class="pre">error_messages</span></code><a class="headerlink" href="#error-messages" title="Permalink to this headline">¶</a></h3>
<dl class="attribute">
<dt id="django.forms.Field.error_messages">
<code class="descclassname">Field.</code><code class="descname">error_messages</code><a class="headerlink" href="#django.forms.Field.error_messages" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>The <code class="docutils literal notranslate"><span class="pre">error_messages</span></code> argument lets you override the default messages that the
field will raise. Pass in a dictionary with keys matching the error messages you
want to override. For example, here is the default error message:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">django</span> <span class="k">import</span> <span class="n">forms</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">generic</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">generic</span><span class="o">.</span><span class="n">clean</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
  <span class="c">...</span>
<span class="gr">ValidationError</span>: <span class="n">[&#39;This field is required.&#39;]</span>
</pre></div>
</div>
<p>And here is a custom error message:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">name</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">error_messages</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;required&#39;</span><span class="p">:</span> <span class="s1">&#39;Please enter your name&#39;</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">name</span><span class="o">.</span><span class="n">clean</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
  <span class="c">...</span>
<span class="gr">ValidationError</span>: <span class="n">[&#39;Please enter your name&#39;]</span>
</pre></div>
</div>
<p>In the <a class="reference internal" href="#built-in-field-classes">built-in Field classes</a> section below, each <code class="docutils literal notranslate"><span class="pre">Field</span></code> defines the
error message keys it uses.</p>
</div>
<div class="section" id="s-validators">
<span id="validators"></span><h3><code class="docutils literal notranslate"><span class="pre">validators</span></code><a class="headerlink" href="#validators" title="Permalink to this headline">¶</a></h3>
<dl class="attribute">
<dt id="django.forms.Field.validators">
<code class="descclassname">Field.</code><code class="descname">validators</code><a class="headerlink" href="#django.forms.Field.validators" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>The <code class="docutils literal notranslate"><span class="pre">validators</span></code> argument lets you provide a list of validation functions
for this field.</p>
<p>See the <a class="reference internal" href="../validators.html"><span class="doc">validators documentation</span></a> for more information.</p>
</div>
<div class="section" id="s-localize">
<span id="localize"></span><h3><code class="docutils literal notranslate"><span class="pre">localize</span></code><a class="headerlink" href="#localize" title="Permalink to this headline">¶</a></h3>
<dl class="attribute">
<dt id="django.forms.Field.localize">
<code class="descclassname">Field.</code><code class="descname">localize</code><a class="headerlink" href="#django.forms.Field.localize" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>The <code class="docutils literal notranslate"><span class="pre">localize</span></code> argument enables the localization of form data input, as well
as the rendered output.</p>
<p>See the <a class="reference internal" href="../../topics/i18n/formatting.html"><span class="doc">format localization</span></a> documentation for
more information.</p>
</div>
<div class="section" id="s-disabled">
<span id="disabled"></span><h3><code class="docutils literal notranslate"><span class="pre">disabled</span></code><a class="headerlink" href="#disabled" title="Permalink to this headline">¶</a></h3>
<dl class="attribute">
<dt id="django.forms.Field.disabled">
<code class="descclassname">Field.</code><code class="descname">disabled</code><a class="headerlink" href="#django.forms.Field.disabled" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>The <code class="docutils literal notranslate"><span class="pre">disabled</span></code> boolean argument, when set to <code class="docutils literal notranslate"><span class="pre">True</span></code>, disables a form field
using the <code class="docutils literal notranslate"><span class="pre">disabled</span></code> HTML attribute so that it won’t be editable by users.
Even if a user tampers with the field’s value submitted to the server, it will
be ignored in favor of the value from the form’s initial data.</p>
</div>
</div>
<div class="section" id="s-checking-if-the-field-data-has-changed">
<span id="checking-if-the-field-data-has-changed"></span><h2>Checking if the field data has changed<a class="headerlink" href="#checking-if-the-field-data-has-changed" title="Permalink to this headline">¶</a></h2>
<div class="section" id="s-has-changed">
<span id="has-changed"></span><h3><code class="docutils literal notranslate"><span class="pre">has_changed()</span></code><a class="headerlink" href="#has-changed" title="Permalink to this headline">¶</a></h3>
<dl class="method">
<dt id="django.forms.Field.has_changed">
<code class="descclassname">Field.</code><code class="descname">has_changed</code>()<a class="reference internal" href="../../_modules/django/forms/fields.html#Field.has_changed"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.Field.has_changed" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>The <code class="docutils literal notranslate"><span class="pre">has_changed()</span></code> method is used to determine if the field value has changed
from the initial value. Returns <code class="docutils literal notranslate"><span class="pre">True</span></code> or <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
<p>See the <a class="reference internal" href="api.html#django.forms.Form.has_changed" title="django.forms.Form.has_changed"><code class="xref py py-class docutils literal notranslate"><span class="pre">Form.has_changed()</span></code></a> documentation for more information.</p>
</div>
</div>
<div class="section" id="s-built-in-field-classes">
<span id="s-built-in-fields"></span><span id="built-in-field-classes"></span><span id="built-in-fields"></span><h2>Built-in <code class="docutils literal notranslate"><span class="pre">Field</span></code> classes<a class="headerlink" href="#built-in-field-classes" title="Permalink to this headline">¶</a></h2>
<p>Naturally, the <code class="docutils literal notranslate"><span class="pre">forms</span></code> library comes with a set of <code class="docutils literal notranslate"><span class="pre">Field</span></code> classes that
represent common validation needs. This section documents each built-in field.</p>
<p>For each field, we describe the default widget used if you don’t specify
<code class="docutils literal notranslate"><span class="pre">widget</span></code>. We also specify the value returned when you provide an empty value
(see the section on <code class="docutils literal notranslate"><span class="pre">required</span></code> above to understand what that means).</p>
<div class="section" id="s-booleanfield">
<span id="booleanfield"></span><h3><code class="docutils literal notranslate"><span class="pre">BooleanField</span></code><a class="headerlink" href="#booleanfield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.BooleanField">
<em class="property">class </em><code class="descname">BooleanField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#BooleanField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.BooleanField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.CheckboxInput" title="django.forms.CheckboxInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">CheckboxInput</span></code></a></li>
<li>Empty value: <code class="docutils literal notranslate"><span class="pre">False</span></code></li>
<li>Normalizes to: A Python <code class="docutils literal notranslate"><span class="pre">True</span></code> or <code class="docutils literal notranslate"><span class="pre">False</span></code> value.</li>
<li>Validates that the value is <code class="docutils literal notranslate"><span class="pre">True</span></code> (e.g. the check box is checked) if
the field has <code class="docutils literal notranslate"><span class="pre">required=True</span></code>.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code></li>
</ul>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Since all <code class="docutils literal notranslate"><span class="pre">Field</span></code> subclasses have <code class="docutils literal notranslate"><span class="pre">required=True</span></code> by default, the
validation condition here is important. If you want to include a boolean
in your form that can be either <code class="docutils literal notranslate"><span class="pre">True</span></code> or <code class="docutils literal notranslate"><span class="pre">False</span></code> (e.g. a checked or
unchecked checkbox), you must remember to pass in <code class="docutils literal notranslate"><span class="pre">required=False</span></code> when
creating the <code class="docutils literal notranslate"><span class="pre">BooleanField</span></code>.</p>
</div>
</dd></dl>

</div>
<div class="section" id="s-charfield">
<span id="charfield"></span><h3><code class="docutils literal notranslate"><span class="pre">CharField</span></code><a class="headerlink" href="#charfield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.CharField">
<em class="property">class </em><code class="descname">CharField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#CharField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.CharField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.TextInput" title="django.forms.TextInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextInput</span></code></a></li>
<li>Empty value: Whatever you’ve given as <a class="reference internal" href="#django.forms.CharField.empty_value" title="django.forms.CharField.empty_value"><code class="xref py py-attr docutils literal notranslate"><span class="pre">empty_value</span></code></a>.</li>
<li>Normalizes to: A Unicode object.</li>
<li>Validates <code class="docutils literal notranslate"><span class="pre">max_length</span></code> or <code class="docutils literal notranslate"><span class="pre">min_length</span></code>, if they are provided.
Otherwise, all inputs are valid.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">max_length</span></code>, <code class="docutils literal notranslate"><span class="pre">min_length</span></code></li>
</ul>
<p>Has three optional arguments for validation:</p>
<dl class="attribute">
<dt id="django.forms.CharField.max_length">
<code class="descname">max_length</code><a class="headerlink" href="#django.forms.CharField.max_length" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="django.forms.CharField.min_length">
<code class="descname">min_length</code><a class="headerlink" href="#django.forms.CharField.min_length" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>If provided, these arguments ensure that the string is at most or at least
the given length.</p>
<dl class="attribute">
<dt id="django.forms.CharField.strip">
<code class="descname">strip</code><a class="headerlink" href="#django.forms.CharField.strip" title="Permalink to this definition">¶</a></dt>
<dd><p>If <code class="docutils literal notranslate"><span class="pre">True</span></code> (default), the value will be stripped of leading and
trailing whitespace.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.forms.CharField.empty_value">
<code class="descname">empty_value</code><a class="headerlink" href="#django.forms.CharField.empty_value" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 1.11.</span> </div>
<p>The value to use to represent “empty”. Defaults to an empty string.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-choicefield">
<span id="choicefield"></span><h3><code class="docutils literal notranslate"><span class="pre">ChoiceField</span></code><a class="headerlink" href="#choicefield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.ChoiceField">
<em class="property">class </em><code class="descname">ChoiceField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#ChoiceField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.ChoiceField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.Select" title="django.forms.Select"><code class="xref py py-class docutils literal notranslate"><span class="pre">Select</span></code></a></li>
<li>Empty value: <code class="docutils literal notranslate"><span class="pre">''</span></code> (an empty string)</li>
<li>Normalizes to: A Unicode object.</li>
<li>Validates that the given value exists in the list of choices.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid_choice</span></code></li>
</ul>
<p>The <code class="docutils literal notranslate"><span class="pre">invalid_choice</span></code> error message may contain <code class="docutils literal notranslate"><span class="pre">%(value)s</span></code>, which will be
replaced with the selected choice.</p>
<p>Takes one extra argument:</p>
<dl class="attribute">
<dt id="django.forms.ChoiceField.choices">
<code class="descname">choices</code><a class="headerlink" href="#django.forms.ChoiceField.choices" title="Permalink to this definition">¶</a></dt>
<dd><p>Either an iterable (e.g., a list or tuple) of 2-tuples to use as
choices for this field, or a callable that returns such an iterable.
This argument accepts the same formats as the <code class="docutils literal notranslate"><span class="pre">choices</span></code> argument to a
model field. See the <a class="reference internal" href="../models/fields.html#field-choices"><span class="std std-ref">model field reference documentation on
choices</span></a> for more details. If the argument is a
callable, it is evaluated each time the field’s form is initialized.
Defaults to an empty list.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-typedchoicefield">
<span id="typedchoicefield"></span><h3><code class="docutils literal notranslate"><span class="pre">TypedChoiceField</span></code><a class="headerlink" href="#typedchoicefield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.TypedChoiceField">
<em class="property">class </em><code class="descname">TypedChoiceField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#TypedChoiceField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.TypedChoiceField" title="Permalink to this definition">¶</a></dt>
<dd><p>Just like a <a class="reference internal" href="#django.forms.ChoiceField" title="django.forms.ChoiceField"><code class="xref py py-class docutils literal notranslate"><span class="pre">ChoiceField</span></code></a>, except <a class="reference internal" href="#django.forms.TypedChoiceField" title="django.forms.TypedChoiceField"><code class="xref py py-class docutils literal notranslate"><span class="pre">TypedChoiceField</span></code></a> takes two
extra arguments, <a class="reference internal" href="#django.forms.TypedChoiceField.coerce" title="django.forms.TypedChoiceField.coerce"><code class="xref py py-attr docutils literal notranslate"><span class="pre">coerce</span></code></a> and <a class="reference internal" href="#django.forms.TypedChoiceField.empty_value" title="django.forms.TypedChoiceField.empty_value"><code class="xref py py-attr docutils literal notranslate"><span class="pre">empty_value</span></code></a>.</p>
<ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.Select" title="django.forms.Select"><code class="xref py py-class docutils literal notranslate"><span class="pre">Select</span></code></a></li>
<li>Empty value: Whatever you’ve given as <a class="reference internal" href="#django.forms.TypedChoiceField.empty_value" title="django.forms.TypedChoiceField.empty_value"><code class="xref py py-attr docutils literal notranslate"><span class="pre">empty_value</span></code></a>.</li>
<li>Normalizes to: A value of the type provided by the <a class="reference internal" href="#django.forms.TypedChoiceField.coerce" title="django.forms.TypedChoiceField.coerce"><code class="xref py py-attr docutils literal notranslate"><span class="pre">coerce</span></code></a>
argument.</li>
<li>Validates that the given value exists in the list of choices and can be
coerced.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid_choice</span></code></li>
</ul>
<p>Takes extra arguments:</p>
<dl class="attribute">
<dt id="django.forms.TypedChoiceField.coerce">
<code class="descname">coerce</code><a class="headerlink" href="#django.forms.TypedChoiceField.coerce" title="Permalink to this definition">¶</a></dt>
<dd><p>A function that takes one argument and returns a coerced value. Examples
include the built-in <code class="docutils literal notranslate"><span class="pre">int</span></code>, <code class="docutils literal notranslate"><span class="pre">float</span></code>, <code class="docutils literal notranslate"><span class="pre">bool</span></code> and other types. Defaults
to an identity function. Note that coercion happens after input
validation, so it is possible to coerce to a value not present in
<code class="docutils literal notranslate"><span class="pre">choices</span></code>.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.forms.TypedChoiceField.empty_value">
<code class="descname">empty_value</code><a class="headerlink" href="#django.forms.TypedChoiceField.empty_value" title="Permalink to this definition">¶</a></dt>
<dd><p>The value to use to represent “empty.” Defaults to the empty string;
<code class="docutils literal notranslate"><span class="pre">None</span></code> is another common choice here. Note that this value will not be
coerced by the function given in the <code class="docutils literal notranslate"><span class="pre">coerce</span></code> argument, so choose it
accordingly.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-datefield">
<span id="datefield"></span><h3><code class="docutils literal notranslate"><span class="pre">DateField</span></code><a class="headerlink" href="#datefield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.DateField">
<em class="property">class </em><code class="descname">DateField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#DateField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.DateField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.DateInput" title="django.forms.DateInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">DateInput</span></code></a></li>
<li>Empty value: <code class="docutils literal notranslate"><span class="pre">None</span></code></li>
<li>Normalizes to: A Python <code class="docutils literal notranslate"><span class="pre">datetime.date</span></code> object.</li>
<li>Validates that the given value is either a <code class="docutils literal notranslate"><span class="pre">datetime.date</span></code>,
<code class="docutils literal notranslate"><span class="pre">datetime.datetime</span></code> or string formatted in a particular date format.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid</span></code></li>
</ul>
<p>Takes one optional argument:</p>
<dl class="attribute">
<dt id="django.forms.DateField.input_formats">
<code class="descname">input_formats</code><a class="headerlink" href="#django.forms.DateField.input_formats" title="Permalink to this definition">¶</a></dt>
<dd><p>A list of formats used to attempt to convert a string to a valid
<code class="docutils literal notranslate"><span class="pre">datetime.date</span></code> object.</p>
</dd></dl>

<p>If no <code class="docutils literal notranslate"><span class="pre">input_formats</span></code> argument is provided, the default input formats are:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">[</span><span class="s1">&#39;%Y-%m-</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">,</span>      <span class="c1"># &#39;2006-10-25&#39;</span>
 <span class="s1">&#39;%m/</span><span class="si">%d</span><span class="s1">/%Y&#39;</span><span class="p">,</span>      <span class="c1"># &#39;10/25/2006&#39;</span>
 <span class="s1">&#39;%m/</span><span class="si">%d</span><span class="s1">/%y&#39;</span><span class="p">]</span>      <span class="c1"># &#39;10/25/06&#39;</span>
</pre></div>
</div>
<p>Additionally, if you specify <a class="reference internal" href="../settings.html#std:setting-USE_L10N"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_L10N=False</span></code></a> in your settings, the
following will also be included in the default input formats:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">[</span><span class="s1">&#39;%b </span><span class="si">%d</span><span class="s1"> %Y&#39;</span><span class="p">,</span>      <span class="c1"># &#39;Oct 25 2006&#39;</span>
 <span class="s1">&#39;%b </span><span class="si">%d</span><span class="s1">, %Y&#39;</span><span class="p">,</span>     <span class="c1"># &#39;Oct 25, 2006&#39;</span>
 <span class="s1">&#39;</span><span class="si">%d</span><span class="s1"> %b %Y&#39;</span><span class="p">,</span>      <span class="c1"># &#39;25 Oct 2006&#39;</span>
 <span class="s1">&#39;</span><span class="si">%d</span><span class="s1"> %b, %Y&#39;</span><span class="p">,</span>     <span class="c1"># &#39;25 Oct, 2006&#39;</span>
 <span class="s1">&#39;%B </span><span class="si">%d</span><span class="s1"> %Y&#39;</span><span class="p">,</span>      <span class="c1"># &#39;October 25 2006&#39;</span>
 <span class="s1">&#39;%B </span><span class="si">%d</span><span class="s1">, %Y&#39;</span><span class="p">,</span>     <span class="c1"># &#39;October 25, 2006&#39;</span>
 <span class="s1">&#39;</span><span class="si">%d</span><span class="s1"> %B %Y&#39;</span><span class="p">,</span>      <span class="c1"># &#39;25 October 2006&#39;</span>
 <span class="s1">&#39;</span><span class="si">%d</span><span class="s1"> %B, %Y&#39;</span><span class="p">]</span>     <span class="c1"># &#39;25 October, 2006&#39;</span>
</pre></div>
</div>
<p>See also <a class="reference internal" href="../../topics/i18n/formatting.html"><span class="doc">format localization</span></a>.</p>
</dd></dl>

</div>
<div class="section" id="s-datetimefield">
<span id="datetimefield"></span><h3><code class="docutils literal notranslate"><span class="pre">DateTimeField</span></code><a class="headerlink" href="#datetimefield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.DateTimeField">
<em class="property">class </em><code class="descname">DateTimeField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#DateTimeField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.DateTimeField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.DateTimeInput" title="django.forms.DateTimeInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">DateTimeInput</span></code></a></li>
<li>Empty value: <code class="docutils literal notranslate"><span class="pre">None</span></code></li>
<li>Normalizes to: A Python <code class="docutils literal notranslate"><span class="pre">datetime.datetime</span></code> object.</li>
<li>Validates that the given value is either a <code class="docutils literal notranslate"><span class="pre">datetime.datetime</span></code>,
<code class="docutils literal notranslate"><span class="pre">datetime.date</span></code> or string formatted in a particular datetime format.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid</span></code></li>
</ul>
<p>Takes one optional argument:</p>
<dl class="attribute">
<dt id="django.forms.DateTimeField.input_formats">
<code class="descname">input_formats</code><a class="headerlink" href="#django.forms.DateTimeField.input_formats" title="Permalink to this definition">¶</a></dt>
<dd><p>A list of formats used to attempt to convert a string to a valid
<code class="docutils literal notranslate"><span class="pre">datetime.datetime</span></code> object.</p>
</dd></dl>

<p>If no <code class="docutils literal notranslate"><span class="pre">input_formats</span></code> argument is provided, the default input formats are:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">[</span><span class="s1">&#39;%Y-%m-</span><span class="si">%d</span><span class="s1"> %H:%M:%S&#39;</span><span class="p">,</span>    <span class="c1"># &#39;2006-10-25 14:30:59&#39;</span>
 <span class="s1">&#39;%Y-%m-</span><span class="si">%d</span><span class="s1"> %H:%M&#39;</span><span class="p">,</span>       <span class="c1"># &#39;2006-10-25 14:30&#39;</span>
 <span class="s1">&#39;%Y-%m-</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">,</span>             <span class="c1"># &#39;2006-10-25&#39;</span>
 <span class="s1">&#39;%m/</span><span class="si">%d</span><span class="s1">/%Y %H:%M:%S&#39;</span><span class="p">,</span>    <span class="c1"># &#39;10/25/2006 14:30:59&#39;</span>
 <span class="s1">&#39;%m/</span><span class="si">%d</span><span class="s1">/%Y %H:%M&#39;</span><span class="p">,</span>       <span class="c1"># &#39;10/25/2006 14:30&#39;</span>
 <span class="s1">&#39;%m/</span><span class="si">%d</span><span class="s1">/%Y&#39;</span><span class="p">,</span>             <span class="c1"># &#39;10/25/2006&#39;</span>
 <span class="s1">&#39;%m/</span><span class="si">%d</span><span class="s1">/%y %H:%M:%S&#39;</span><span class="p">,</span>    <span class="c1"># &#39;10/25/06 14:30:59&#39;</span>
 <span class="s1">&#39;%m/</span><span class="si">%d</span><span class="s1">/%y %H:%M&#39;</span><span class="p">,</span>       <span class="c1"># &#39;10/25/06 14:30&#39;</span>
 <span class="s1">&#39;%m/</span><span class="si">%d</span><span class="s1">/%y&#39;</span><span class="p">]</span>             <span class="c1"># &#39;10/25/06&#39;</span>
</pre></div>
</div>
<p>See also <a class="reference internal" href="../../topics/i18n/formatting.html"><span class="doc">format localization</span></a>.</p>
</dd></dl>

</div>
<div class="section" id="s-decimalfield">
<span id="decimalfield"></span><h3><code class="docutils literal notranslate"><span class="pre">DecimalField</span></code><a class="headerlink" href="#decimalfield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.DecimalField">
<em class="property">class </em><code class="descname">DecimalField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#DecimalField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.DecimalField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.NumberInput" title="django.forms.NumberInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">NumberInput</span></code></a> when <a class="reference internal" href="#django.forms.Field.localize" title="django.forms.Field.localize"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Field.localize</span></code></a> is
<code class="docutils literal notranslate"><span class="pre">False</span></code>, else <a class="reference internal" href="widgets.html#django.forms.TextInput" title="django.forms.TextInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextInput</span></code></a>.</li>
<li>Empty value: <code class="docutils literal notranslate"><span class="pre">None</span></code></li>
<li>Normalizes to: A Python <code class="docutils literal notranslate"><span class="pre">decimal</span></code>.</li>
<li>Validates that the given value is a decimal. Leading and trailing
whitespace is ignored.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid</span></code>, <code class="docutils literal notranslate"><span class="pre">max_value</span></code>,
<code class="docutils literal notranslate"><span class="pre">min_value</span></code>, <code class="docutils literal notranslate"><span class="pre">max_digits</span></code>, <code class="docutils literal notranslate"><span class="pre">max_decimal_places</span></code>,
<code class="docutils literal notranslate"><span class="pre">max_whole_digits</span></code></li>
</ul>
<p>The <code class="docutils literal notranslate"><span class="pre">max_value</span></code> and <code class="docutils literal notranslate"><span class="pre">min_value</span></code> error messages may contain
<code class="docutils literal notranslate"><span class="pre">%(limit_value)s</span></code>, which will be substituted by the appropriate limit.
Similarly, the <code class="docutils literal notranslate"><span class="pre">max_digits</span></code>, <code class="docutils literal notranslate"><span class="pre">max_decimal_places</span></code> and
<code class="docutils literal notranslate"><span class="pre">max_whole_digits</span></code> error messages may contain <code class="docutils literal notranslate"><span class="pre">%(max)s</span></code>.</p>
<p>Takes four optional arguments:</p>
<dl class="attribute">
<dt id="django.forms.DecimalField.max_value">
<code class="descname">max_value</code><a class="headerlink" href="#django.forms.DecimalField.max_value" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="django.forms.DecimalField.min_value">
<code class="descname">min_value</code><a class="headerlink" href="#django.forms.DecimalField.min_value" title="Permalink to this definition">¶</a></dt>
<dd><p>These control the range of values permitted in the field, and should be
given as <code class="docutils literal notranslate"><span class="pre">decimal.Decimal</span></code> values.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.forms.DecimalField.max_digits">
<code class="descname">max_digits</code><a class="headerlink" href="#django.forms.DecimalField.max_digits" title="Permalink to this definition">¶</a></dt>
<dd><p>The maximum number of digits (those before the decimal point plus those
after the decimal point, with leading zeros stripped) permitted in the
value.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.forms.DecimalField.decimal_places">
<code class="descname">decimal_places</code><a class="headerlink" href="#django.forms.DecimalField.decimal_places" title="Permalink to this definition">¶</a></dt>
<dd><p>The maximum number of decimal places permitted.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-durationfield">
<span id="durationfield"></span><h3><code class="docutils literal notranslate"><span class="pre">DurationField</span></code><a class="headerlink" href="#durationfield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.DurationField">
<em class="property">class </em><code class="descname">DurationField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#DurationField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.DurationField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.TextInput" title="django.forms.TextInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextInput</span></code></a></li>
<li>Empty value: <code class="docutils literal notranslate"><span class="pre">None</span></code></li>
<li>Normalizes to: A Python <a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.timedelta" title="(in Python v3.7)"><code class="xref py py-class docutils literal notranslate"><span class="pre">timedelta</span></code></a>.</li>
<li>Validates that the given value is a string which can be converted into a
<code class="docutils literal notranslate"><span class="pre">timedelta</span></code>.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid</span></code>.</li>
</ul>
<p>Accepts any format understood by
<a class="reference internal" href="../utils.html#django.utils.dateparse.parse_duration" title="django.utils.dateparse.parse_duration"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse_duration()</span></code></a>.</p>
</dd></dl>

</div>
<div class="section" id="s-emailfield">
<span id="emailfield"></span><h3><code class="docutils literal notranslate"><span class="pre">EmailField</span></code><a class="headerlink" href="#emailfield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.EmailField">
<em class="property">class </em><code class="descname">EmailField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#EmailField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.EmailField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.EmailInput" title="django.forms.EmailInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">EmailInput</span></code></a></li>
<li>Empty value: <code class="docutils literal notranslate"><span class="pre">''</span></code> (an empty string)</li>
<li>Normalizes to: A Unicode object.</li>
<li>Validates that the given value is a valid email address, using a
moderately complex regular expression.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid</span></code></li>
</ul>
<p>Has two optional arguments for validation, <code class="docutils literal notranslate"><span class="pre">max_length</span></code> and <code class="docutils literal notranslate"><span class="pre">min_length</span></code>.
If provided, these arguments ensure that the string is at most or at least the
given length.</p>
</dd></dl>

</div>
<div class="section" id="s-filefield">
<span id="filefield"></span><h3><code class="docutils literal notranslate"><span class="pre">FileField</span></code><a class="headerlink" href="#filefield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.FileField">
<em class="property">class </em><code class="descname">FileField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#FileField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.FileField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.ClearableFileInput" title="django.forms.ClearableFileInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">ClearableFileInput</span></code></a></li>
<li>Empty value: <code class="docutils literal notranslate"><span class="pre">None</span></code></li>
<li>Normalizes to: An <code class="docutils literal notranslate"><span class="pre">UploadedFile</span></code> object that wraps the file content
and file name into a single object.</li>
<li>Can validate that non-empty file data has been bound to the form.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid</span></code>, <code class="docutils literal notranslate"><span class="pre">missing</span></code>, <code class="docutils literal notranslate"><span class="pre">empty</span></code>,
<code class="docutils literal notranslate"><span class="pre">max_length</span></code></li>
</ul>
<p>Has two optional arguments for validation, <code class="docutils literal notranslate"><span class="pre">max_length</span></code> and
<code class="docutils literal notranslate"><span class="pre">allow_empty_file</span></code>. If provided, these ensure that the file name is at
most the given length, and that validation will succeed even if the file
content is empty.</p>
<p>To learn more about the <code class="docutils literal notranslate"><span class="pre">UploadedFile</span></code> object, see the <a class="reference internal" href="../../topics/http/file-uploads.html"><span class="doc">file uploads
documentation</span></a>.</p>
<p>When you use a <code class="docutils literal notranslate"><span class="pre">FileField</span></code> in a form, you must also remember to
<a class="reference internal" href="api.html#binding-uploaded-files"><span class="std std-ref">bind the file data to the form</span></a>.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">max_length</span></code> error refers to the length of the filename. In the error
message for that key, <code class="docutils literal notranslate"><span class="pre">%(max)d</span></code> will be replaced with the maximum filename
length and <code class="docutils literal notranslate"><span class="pre">%(length)d</span></code> will be replaced with the current filename length.</p>
</dd></dl>

</div>
<div class="section" id="s-filepathfield">
<span id="filepathfield"></span><h3><code class="docutils literal notranslate"><span class="pre">FilePathField</span></code><a class="headerlink" href="#filepathfield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.FilePathField">
<em class="property">class </em><code class="descname">FilePathField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#FilePathField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.FilePathField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.Select" title="django.forms.Select"><code class="xref py py-class docutils literal notranslate"><span class="pre">Select</span></code></a></li>
<li>Empty value: <code class="docutils literal notranslate"><span class="pre">None</span></code></li>
<li>Normalizes to: A unicode object</li>
<li>Validates that the selected choice exists in the list of choices.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid_choice</span></code></li>
</ul>
<p>The field allows choosing from files inside a certain directory. It takes five
extra arguments; only <code class="docutils literal notranslate"><span class="pre">path</span></code> is required:</p>
<dl class="attribute">
<dt id="django.forms.FilePathField.path">
<code class="descname">path</code><a class="headerlink" href="#django.forms.FilePathField.path" title="Permalink to this definition">¶</a></dt>
<dd><p>The absolute path to the directory whose contents you want listed. This
directory must exist.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.forms.FilePathField.recursive">
<code class="descname">recursive</code><a class="headerlink" href="#django.forms.FilePathField.recursive" title="Permalink to this definition">¶</a></dt>
<dd><p>If <code class="docutils literal notranslate"><span class="pre">False</span></code> (the default) only the direct contents of <code class="docutils literal notranslate"><span class="pre">path</span></code> will be
offered as choices. If <code class="docutils literal notranslate"><span class="pre">True</span></code>, the directory will be descended into
recursively and all descendants will be listed as choices.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.forms.FilePathField.match">
<code class="descname">match</code><a class="headerlink" href="#django.forms.FilePathField.match" title="Permalink to this definition">¶</a></dt>
<dd><p>A regular expression pattern; only files with names matching this expression
will be allowed as choices.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.forms.FilePathField.allow_files">
<code class="descname">allow_files</code><a class="headerlink" href="#django.forms.FilePathField.allow_files" title="Permalink to this definition">¶</a></dt>
<dd><p>Optional.  Either <code class="docutils literal notranslate"><span class="pre">True</span></code> or <code class="docutils literal notranslate"><span class="pre">False</span></code>.  Default is <code class="docutils literal notranslate"><span class="pre">True</span></code>.  Specifies
whether files in the specified location should be included.  Either this or
<a class="reference internal" href="#django.forms.FilePathField.allow_folders" title="django.forms.FilePathField.allow_folders"><code class="xref py py-attr docutils literal notranslate"><span class="pre">allow_folders</span></code></a> must be <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.forms.FilePathField.allow_folders">
<code class="descname">allow_folders</code><a class="headerlink" href="#django.forms.FilePathField.allow_folders" title="Permalink to this definition">¶</a></dt>
<dd><p>Optional.  Either <code class="docutils literal notranslate"><span class="pre">True</span></code> or <code class="docutils literal notranslate"><span class="pre">False</span></code>.  Default is <code class="docutils literal notranslate"><span class="pre">False</span></code>.  Specifies
whether folders in the specified location should be included.  Either this or
<a class="reference internal" href="#django.forms.FilePathField.allow_files" title="django.forms.FilePathField.allow_files"><code class="xref py py-attr docutils literal notranslate"><span class="pre">allow_files</span></code></a> must be <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-floatfield">
<span id="floatfield"></span><h3><code class="docutils literal notranslate"><span class="pre">FloatField</span></code><a class="headerlink" href="#floatfield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.FloatField">
<em class="property">class </em><code class="descname">FloatField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#FloatField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.FloatField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.NumberInput" title="django.forms.NumberInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">NumberInput</span></code></a> when <a class="reference internal" href="#django.forms.Field.localize" title="django.forms.Field.localize"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Field.localize</span></code></a> is
<code class="docutils literal notranslate"><span class="pre">False</span></code>, else <a class="reference internal" href="widgets.html#django.forms.TextInput" title="django.forms.TextInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextInput</span></code></a>.</li>
<li>Empty value: <code class="docutils literal notranslate"><span class="pre">None</span></code></li>
<li>Normalizes to: A Python float.</li>
<li>Validates that the given value is a float. Leading and trailing
whitespace is allowed, as in Python’s <code class="docutils literal notranslate"><span class="pre">float()</span></code> function.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid</span></code>, <code class="docutils literal notranslate"><span class="pre">max_value</span></code>,
<code class="docutils literal notranslate"><span class="pre">min_value</span></code></li>
</ul>
<p>Takes two optional arguments for validation, <code class="docutils literal notranslate"><span class="pre">max_value</span></code> and <code class="docutils literal notranslate"><span class="pre">min_value</span></code>.
These control the range of values permitted in the field.</p>
</dd></dl>

</div>
<div class="section" id="s-imagefield">
<span id="imagefield"></span><h3><code class="docutils literal notranslate"><span class="pre">ImageField</span></code><a class="headerlink" href="#imagefield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.ImageField">
<em class="property">class </em><code class="descname">ImageField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#ImageField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.ImageField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.ClearableFileInput" title="django.forms.ClearableFileInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">ClearableFileInput</span></code></a></li>
<li>Empty value: <code class="docutils literal notranslate"><span class="pre">None</span></code></li>
<li>Normalizes to: An <code class="docutils literal notranslate"><span class="pre">UploadedFile</span></code> object that wraps the file content
and file name into a single object.</li>
<li>Validates that file data has been bound to the form, and that the
file is of an image format understood by Pillow.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid</span></code>, <code class="docutils literal notranslate"><span class="pre">missing</span></code>, <code class="docutils literal notranslate"><span class="pre">empty</span></code>,
<code class="docutils literal notranslate"><span class="pre">invalid_image</span></code></li>
</ul>
<p>Using an <code class="docutils literal notranslate"><span class="pre">ImageField</span></code> requires that <a class="reference external" href="https://pillow.readthedocs.io/en/latest/">Pillow</a> is installed with support
for the image formats you use. If you encounter a <code class="docutils literal notranslate"><span class="pre">corrupt</span> <span class="pre">image</span></code> error
when you upload an image, it usually means that Pillow doesn’t understand
its format. To fix this, install the appropriate library and reinstall
Pillow.</p>
<p>When you use an <code class="docutils literal notranslate"><span class="pre">ImageField</span></code> on a form, you must also remember to
<a class="reference internal" href="api.html#binding-uploaded-files"><span class="std std-ref">bind the file data to the form</span></a>.</p>
<p>After the field has been cleaned and validated, the <code class="docutils literal notranslate"><span class="pre">UploadedFile</span></code>
object will have an additional <code class="docutils literal notranslate"><span class="pre">image</span></code> attribute containing the Pillow
<a class="reference external" href="https://pillow.readthedocs.io/en/latest/reference/Image.html">Image</a> instance used to check if the file was a valid image. Also,
<code class="docutils literal notranslate"><span class="pre">UploadedFile.content_type</span></code> will be updated with the image’s content type
if Pillow can determine it, otherwise it will be set to <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
</dd></dl>

</div>
<div class="section" id="s-integerfield">
<span id="integerfield"></span><h3><code class="docutils literal notranslate"><span class="pre">IntegerField</span></code><a class="headerlink" href="#integerfield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.IntegerField">
<em class="property">class </em><code class="descname">IntegerField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#IntegerField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.IntegerField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.NumberInput" title="django.forms.NumberInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">NumberInput</span></code></a> when <a class="reference internal" href="#django.forms.Field.localize" title="django.forms.Field.localize"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Field.localize</span></code></a> is
<code class="docutils literal notranslate"><span class="pre">False</span></code>, else <a class="reference internal" href="widgets.html#django.forms.TextInput" title="django.forms.TextInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextInput</span></code></a>.</li>
<li>Empty value: <code class="docutils literal notranslate"><span class="pre">None</span></code></li>
<li>Normalizes to: A Python integer or long integer.</li>
<li>Validates that the given value is an integer. Leading and trailing
whitespace is allowed, as in Python’s <code class="docutils literal notranslate"><span class="pre">int()</span></code> function.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid</span></code>, <code class="docutils literal notranslate"><span class="pre">max_value</span></code>,
<code class="docutils literal notranslate"><span class="pre">min_value</span></code></li>
</ul>
<p>The <code class="docutils literal notranslate"><span class="pre">max_value</span></code> and <code class="docutils literal notranslate"><span class="pre">min_value</span></code> error messages may contain
<code class="docutils literal notranslate"><span class="pre">%(limit_value)s</span></code>, which will be substituted by the appropriate limit.</p>
<p>Takes two optional arguments for validation:</p>
<dl class="attribute">
<dt id="django.forms.IntegerField.max_value">
<code class="descname">max_value</code><a class="headerlink" href="#django.forms.IntegerField.max_value" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="django.forms.IntegerField.min_value">
<code class="descname">min_value</code><a class="headerlink" href="#django.forms.IntegerField.min_value" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>These control the range of values permitted in the field.</p>
</dd></dl>

</div>
<div class="section" id="s-genericipaddressfield">
<span id="genericipaddressfield"></span><h3><code class="docutils literal notranslate"><span class="pre">GenericIPAddressField</span></code><a class="headerlink" href="#genericipaddressfield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.GenericIPAddressField">
<em class="property">class </em><code class="descname">GenericIPAddressField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#GenericIPAddressField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.GenericIPAddressField" title="Permalink to this definition">¶</a></dt>
<dd><p>A field containing either an IPv4 or an IPv6 address.</p>
<ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.TextInput" title="django.forms.TextInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextInput</span></code></a></li>
<li>Empty value: <code class="docutils literal notranslate"><span class="pre">''</span></code> (an empty string)</li>
<li>Normalizes to: A Unicode object. IPv6 addresses are
normalized as described below.</li>
<li>Validates that the given value is a valid IP address.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid</span></code></li>
</ul>
<p>The IPv6 address normalization follows <span class="target" id="index-0"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc4291.html#section-2.2"><strong>RFC 4291#section-2.2</strong></a> section 2.2,
including using the IPv4 format suggested in paragraph 3 of that section, like
<code class="docutils literal notranslate"><span class="pre">::ffff:192.0.2.0</span></code>. For example, <code class="docutils literal notranslate"><span class="pre">2001:0::0:01</span></code> would be normalized to
<code class="docutils literal notranslate"><span class="pre">2001::1</span></code>, and <code class="docutils literal notranslate"><span class="pre">::ffff:0a0a:0a0a</span></code> to <code class="docutils literal notranslate"><span class="pre">::ffff:10.10.10.10</span></code>. All characters
are converted to lowercase.</p>
<p>Takes two optional arguments:</p>
<dl class="attribute">
<dt id="django.forms.GenericIPAddressField.protocol">
<code class="descname">protocol</code><a class="headerlink" href="#django.forms.GenericIPAddressField.protocol" title="Permalink to this definition">¶</a></dt>
<dd><p>Limits valid inputs to the specified protocol.
Accepted values are <code class="docutils literal notranslate"><span class="pre">both</span></code> (default), <code class="docutils literal notranslate"><span class="pre">IPv4</span></code>
or <code class="docutils literal notranslate"><span class="pre">IPv6</span></code>. Matching is case insensitive.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.forms.GenericIPAddressField.unpack_ipv4">
<code class="descname">unpack_ipv4</code><a class="headerlink" href="#django.forms.GenericIPAddressField.unpack_ipv4" title="Permalink to this definition">¶</a></dt>
<dd><p>Unpacks IPv4 mapped addresses like <code class="docutils literal notranslate"><span class="pre">::ffff:192.0.2.1</span></code>.
If this option is enabled that address would be unpacked to
<code class="docutils literal notranslate"><span class="pre">192.0.2.1</span></code>. Default is disabled. Can only be used
when <code class="docutils literal notranslate"><span class="pre">protocol</span></code> is set to <code class="docutils literal notranslate"><span class="pre">'both'</span></code>.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-multiplechoicefield">
<span id="multiplechoicefield"></span><h3><code class="docutils literal notranslate"><span class="pre">MultipleChoiceField</span></code><a class="headerlink" href="#multiplechoicefield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.MultipleChoiceField">
<em class="property">class </em><code class="descname">MultipleChoiceField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#MultipleChoiceField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.MultipleChoiceField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.SelectMultiple" title="django.forms.SelectMultiple"><code class="xref py py-class docutils literal notranslate"><span class="pre">SelectMultiple</span></code></a></li>
<li>Empty value: <code class="docutils literal notranslate"><span class="pre">[]</span></code> (an empty list)</li>
<li>Normalizes to: A list of Unicode objects.</li>
<li>Validates that every value in the given list of values exists in the list
of choices.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid_choice</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid_list</span></code></li>
</ul>
<p>The <code class="docutils literal notranslate"><span class="pre">invalid_choice</span></code> error message may contain <code class="docutils literal notranslate"><span class="pre">%(value)s</span></code>, which will be
replaced with the selected choice.</p>
<p>Takes one extra required argument, <code class="docutils literal notranslate"><span class="pre">choices</span></code>, as for <a class="reference internal" href="#django.forms.ChoiceField" title="django.forms.ChoiceField"><code class="xref py py-class docutils literal notranslate"><span class="pre">ChoiceField</span></code></a>.</p>
</dd></dl>

</div>
<div class="section" id="s-typedmultiplechoicefield">
<span id="typedmultiplechoicefield"></span><h3><code class="docutils literal notranslate"><span class="pre">TypedMultipleChoiceField</span></code><a class="headerlink" href="#typedmultiplechoicefield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.TypedMultipleChoiceField">
<em class="property">class </em><code class="descname">TypedMultipleChoiceField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#TypedMultipleChoiceField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.TypedMultipleChoiceField" title="Permalink to this definition">¶</a></dt>
<dd><p>Just like a <a class="reference internal" href="#django.forms.MultipleChoiceField" title="django.forms.MultipleChoiceField"><code class="xref py py-class docutils literal notranslate"><span class="pre">MultipleChoiceField</span></code></a>, except <a class="reference internal" href="#django.forms.TypedMultipleChoiceField" title="django.forms.TypedMultipleChoiceField"><code class="xref py py-class docutils literal notranslate"><span class="pre">TypedMultipleChoiceField</span></code></a>
takes two extra arguments, <code class="docutils literal notranslate"><span class="pre">coerce</span></code> and <code class="docutils literal notranslate"><span class="pre">empty_value</span></code>.</p>
<ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.SelectMultiple" title="django.forms.SelectMultiple"><code class="xref py py-class docutils literal notranslate"><span class="pre">SelectMultiple</span></code></a></li>
<li>Empty value: Whatever you’ve given as <code class="docutils literal notranslate"><span class="pre">empty_value</span></code></li>
<li>Normalizes to: A list of values of the type provided by the <code class="docutils literal notranslate"><span class="pre">coerce</span></code>
argument.</li>
<li>Validates that the given values exists in the list of choices and can be
coerced.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid_choice</span></code></li>
</ul>
<p>The <code class="docutils literal notranslate"><span class="pre">invalid_choice</span></code> error message may contain <code class="docutils literal notranslate"><span class="pre">%(value)s</span></code>, which will be
replaced with the selected choice.</p>
<p>Takes two extra arguments, <code class="docutils literal notranslate"><span class="pre">coerce</span></code> and <code class="docutils literal notranslate"><span class="pre">empty_value</span></code>, as for
<a class="reference internal" href="#django.forms.TypedChoiceField" title="django.forms.TypedChoiceField"><code class="xref py py-class docutils literal notranslate"><span class="pre">TypedChoiceField</span></code></a>.</p>
</dd></dl>

</div>
<div class="section" id="s-nullbooleanfield">
<span id="nullbooleanfield"></span><h3><code class="docutils literal notranslate"><span class="pre">NullBooleanField</span></code><a class="headerlink" href="#nullbooleanfield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.NullBooleanField">
<em class="property">class </em><code class="descname">NullBooleanField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#NullBooleanField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.NullBooleanField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.NullBooleanSelect" title="django.forms.NullBooleanSelect"><code class="xref py py-class docutils literal notranslate"><span class="pre">NullBooleanSelect</span></code></a></li>
<li>Empty value: <code class="docutils literal notranslate"><span class="pre">None</span></code></li>
<li>Normalizes to: A Python <code class="docutils literal notranslate"><span class="pre">True</span></code>, <code class="docutils literal notranslate"><span class="pre">False</span></code> or <code class="docutils literal notranslate"><span class="pre">None</span></code> value.</li>
<li>Validates nothing (i.e., it never raises a <code class="docutils literal notranslate"><span class="pre">ValidationError</span></code>).</li>
</ul>
</dd></dl>

</div>
<div class="section" id="s-regexfield">
<span id="regexfield"></span><h3><code class="docutils literal notranslate"><span class="pre">RegexField</span></code><a class="headerlink" href="#regexfield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.RegexField">
<em class="property">class </em><code class="descname">RegexField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#RegexField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.RegexField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.TextInput" title="django.forms.TextInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextInput</span></code></a></li>
<li>Empty value: <code class="docutils literal notranslate"><span class="pre">''</span></code> (an empty string)</li>
<li>Normalizes to: A Unicode object.</li>
<li>Validates that the given value matches against a certain regular
expression.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid</span></code></li>
</ul>
<p>Takes one required argument:</p>
<dl class="attribute">
<dt id="django.forms.RegexField.regex">
<code class="descname">regex</code><a class="headerlink" href="#django.forms.RegexField.regex" title="Permalink to this definition">¶</a></dt>
<dd><p>A regular expression specified either as a string or a compiled regular
expression object.</p>
</dd></dl>

<p>Also takes <code class="docutils literal notranslate"><span class="pre">max_length</span></code>, <code class="docutils literal notranslate"><span class="pre">min_length</span></code>, and <code class="docutils literal notranslate"><span class="pre">strip</span></code>, which work just
as they do for <a class="reference internal" href="#django.forms.CharField" title="django.forms.CharField"><code class="xref py py-class docutils literal notranslate"><span class="pre">CharField</span></code></a>.</p>
<dl class="attribute">
<dt id="django.forms.RegexField.strip">
<code class="descname">strip</code><a class="headerlink" href="#django.forms.RegexField.strip" title="Permalink to this definition">¶</a></dt>
<dd><p>Defaults to <code class="docutils literal notranslate"><span class="pre">False</span></code>. If enabled, stripping will be applied before the
regex validation.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-slugfield">
<span id="slugfield"></span><h3><code class="docutils literal notranslate"><span class="pre">SlugField</span></code><a class="headerlink" href="#slugfield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.SlugField">
<em class="property">class </em><code class="descname">SlugField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#SlugField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.SlugField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.TextInput" title="django.forms.TextInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextInput</span></code></a></li>
<li>Empty value: <code class="docutils literal notranslate"><span class="pre">''</span></code> (an empty string)</li>
<li>Normalizes to: A Unicode object.</li>
<li>Validates that the given value contains only letters, numbers,
underscores, and hyphens.</li>
<li>Error messages: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid</span></code></li>
</ul>
<p>This field is intended for use in representing a model
<a class="reference internal" href="../models/fields.html#django.db.models.SlugField" title="django.db.models.SlugField"><code class="xref py py-class docutils literal notranslate"><span class="pre">SlugField</span></code></a> in forms.</p>
<p>Takes an optional parameter:</p>
<dl class="attribute">
<dt id="django.forms.SlugField.allow_unicode">
<code class="descname">allow_unicode</code><a class="headerlink" href="#django.forms.SlugField.allow_unicode" title="Permalink to this definition">¶</a></dt>
<dd><p>A boolean instructing the field to accept Unicode letters in addition
to ASCII letters. Defaults to <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-timefield">
<span id="timefield"></span><h3><code class="docutils literal notranslate"><span class="pre">TimeField</span></code><a class="headerlink" href="#timefield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.TimeField">
<em class="property">class </em><code class="descname">TimeField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#TimeField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.TimeField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.TextInput" title="django.forms.TextInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextInput</span></code></a></li>
<li>Empty value: <code class="docutils literal notranslate"><span class="pre">None</span></code></li>
<li>Normalizes to: A Python <code class="docutils literal notranslate"><span class="pre">datetime.time</span></code> object.</li>
<li>Validates that the given value is either a <code class="docutils literal notranslate"><span class="pre">datetime.time</span></code> or string
formatted in a particular time format.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid</span></code></li>
</ul>
<p>Takes one optional argument:</p>
<dl class="attribute">
<dt id="django.forms.TimeField.input_formats">
<code class="descname">input_formats</code><a class="headerlink" href="#django.forms.TimeField.input_formats" title="Permalink to this definition">¶</a></dt>
<dd><p>A list of formats used to attempt to convert a string to a valid
<code class="docutils literal notranslate"><span class="pre">datetime.time</span></code> object.</p>
</dd></dl>

<p>If no <code class="docutils literal notranslate"><span class="pre">input_formats</span></code> argument is provided, the default input formats are:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="s1">&#39;%H:%M:%S&#39;</span><span class="p">,</span>     <span class="c1"># &#39;14:30:59&#39;</span>
<span class="s1">&#39;%H:%M&#39;</span><span class="p">,</span>        <span class="c1"># &#39;14:30&#39;</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="s-urlfield">
<span id="urlfield"></span><h3><code class="docutils literal notranslate"><span class="pre">URLField</span></code><a class="headerlink" href="#urlfield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.URLField">
<em class="property">class </em><code class="descname">URLField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#URLField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.URLField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.URLInput" title="django.forms.URLInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">URLInput</span></code></a></li>
<li>Empty value: <code class="docutils literal notranslate"><span class="pre">''</span></code> (an empty string)</li>
<li>Normalizes to: A Unicode object.</li>
<li>Validates that the given value is a valid URL.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid</span></code></li>
</ul>
<p>Takes the following optional arguments:</p>
<dl class="attribute">
<dt id="django.forms.URLField.max_length">
<code class="descname">max_length</code><a class="headerlink" href="#django.forms.URLField.max_length" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="django.forms.URLField.min_length">
<code class="descname">min_length</code><a class="headerlink" href="#django.forms.URLField.min_length" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>These are the same as <code class="docutils literal notranslate"><span class="pre">CharField.max_length</span></code> and <code class="docutils literal notranslate"><span class="pre">CharField.min_length</span></code>.</p>
</dd></dl>

</div>
<div class="section" id="s-uuidfield">
<span id="uuidfield"></span><h3><code class="docutils literal notranslate"><span class="pre">UUIDField</span></code><a class="headerlink" href="#uuidfield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.UUIDField">
<em class="property">class </em><code class="descname">UUIDField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#UUIDField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.UUIDField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.TextInput" title="django.forms.TextInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextInput</span></code></a></li>
<li>Empty value: <code class="docutils literal notranslate"><span class="pre">''</span></code> (an empty string)</li>
<li>Normalizes to: A <a class="reference external" href="https://docs.python.org/3/library/uuid.html#uuid.UUID" title="(in Python v3.7)"><code class="xref py py-class docutils literal notranslate"><span class="pre">UUID</span></code></a> object.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid</span></code></li>
</ul>
<p>This field will accept any string format accepted as the <code class="docutils literal notranslate"><span class="pre">hex</span></code> argument
to the <a class="reference external" href="https://docs.python.org/3/library/uuid.html#uuid.UUID" title="(in Python v3.7)"><code class="xref py py-class docutils literal notranslate"><span class="pre">UUID</span></code></a> constructor.</p>
</dd></dl>

</div>
</div>
<div class="section" id="s-slightly-complex-built-in-field-classes">
<span id="slightly-complex-built-in-field-classes"></span><h2>Slightly complex built-in <code class="docutils literal notranslate"><span class="pre">Field</span></code> classes<a class="headerlink" href="#slightly-complex-built-in-field-classes" title="Permalink to this headline">¶</a></h2>
<div class="section" id="s-combofield">
<span id="combofield"></span><h3><code class="docutils literal notranslate"><span class="pre">ComboField</span></code><a class="headerlink" href="#combofield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.ComboField">
<em class="property">class </em><code class="descname">ComboField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#ComboField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.ComboField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.TextInput" title="django.forms.TextInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextInput</span></code></a></li>
<li>Empty value: <code class="docutils literal notranslate"><span class="pre">''</span></code> (an empty string)</li>
<li>Normalizes to: A Unicode object.</li>
<li>Validates the given value against each of the fields specified
as an argument to the <code class="docutils literal notranslate"><span class="pre">ComboField</span></code>.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid</span></code></li>
</ul>
<p>Takes one extra required argument:</p>
<dl class="attribute">
<dt id="django.forms.ComboField.fields">
<code class="descname">fields</code><a class="headerlink" href="#django.forms.ComboField.fields" title="Permalink to this definition">¶</a></dt>
<dd><p>The list of fields that should be used to validate the field’s value (in
the order in which they are provided).</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">django.forms</span> <span class="k">import</span> <span class="n">ComboField</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">ComboField</span><span class="p">(</span><span class="n">fields</span><span class="o">=</span><span class="p">[</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">20</span><span class="p">),</span> <span class="n">EmailField</span><span class="p">()])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">clean</span><span class="p">(</span><span class="s1">&#39;test@example.com&#39;</span><span class="p">)</span>
<span class="go">&#39;test@example.com&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">clean</span><span class="p">(</span><span class="s1">&#39;longemailaddress@example.com&#39;</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">ValidationError</span>: <span class="n">[&#39;Ensure this value has at most 20 characters (it has 28).&#39;]</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-multivaluefield">
<span id="multivaluefield"></span><h3><code class="docutils literal notranslate"><span class="pre">MultiValueField</span></code><a class="headerlink" href="#multivaluefield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.MultiValueField">
<em class="property">class </em><code class="descname">MultiValueField</code>(<em>fields=()</em>, <em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#MultiValueField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.MultiValueField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.TextInput" title="django.forms.TextInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextInput</span></code></a></li>
<li>Empty value: <code class="docutils literal notranslate"><span class="pre">''</span></code> (an empty string)</li>
<li>Normalizes to: the type returned by the <code class="docutils literal notranslate"><span class="pre">compress</span></code> method of the subclass.</li>
<li>Validates the given value against each of the fields specified
as an argument to the <code class="docutils literal notranslate"><span class="pre">MultiValueField</span></code>.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid</span></code>, <code class="docutils literal notranslate"><span class="pre">incomplete</span></code></li>
</ul>
<p>Aggregates the logic of multiple fields that together produce a single
value.</p>
<p>This field is abstract and must be subclassed. In contrast with the
single-value fields, subclasses of <a class="reference internal" href="#django.forms.MultiValueField" title="django.forms.MultiValueField"><code class="xref py py-class docutils literal notranslate"><span class="pre">MultiValueField</span></code></a> must not
implement <a class="reference internal" href="#django.forms.Field.clean" title="django.forms.Field.clean"><code class="xref py py-meth docutils literal notranslate"><span class="pre">clean()</span></code></a> but instead - implement
<a class="reference internal" href="#django.forms.MultiValueField.compress" title="django.forms.MultiValueField.compress"><code class="xref py py-meth docutils literal notranslate"><span class="pre">compress()</span></code></a>.</p>
<p>Takes one extra required argument:</p>
<dl class="attribute">
<dt id="django.forms.MultiValueField.fields">
<code class="descname">fields</code><a class="headerlink" href="#django.forms.MultiValueField.fields" title="Permalink to this definition">¶</a></dt>
<dd><p>A tuple of fields whose values are cleaned and subsequently combined
into a single value.  Each value of the field is cleaned by the
corresponding field in <code class="docutils literal notranslate"><span class="pre">fields</span></code> – the first value is cleaned by the
first field, the second value is cleaned by the second field, etc.
Once all fields are cleaned, the list of clean values is combined into
a single value by <a class="reference internal" href="#django.forms.MultiValueField.compress" title="django.forms.MultiValueField.compress"><code class="xref py py-meth docutils literal notranslate"><span class="pre">compress()</span></code></a>.</p>
</dd></dl>

<p>Also takes some optional arguments:</p>
<dl class="attribute">
<dt id="django.forms.MultiValueField.require_all_fields">
<code class="descname">require_all_fields</code><a class="headerlink" href="#django.forms.MultiValueField.require_all_fields" title="Permalink to this definition">¶</a></dt>
<dd><p>Defaults to <code class="docutils literal notranslate"><span class="pre">True</span></code>, in which case a <code class="docutils literal notranslate"><span class="pre">required</span></code> validation error
will be raised if no value is supplied for any field.</p>
<p>When set to <code class="docutils literal notranslate"><span class="pre">False</span></code>, the <a class="reference internal" href="#django.forms.Field.required" title="django.forms.Field.required"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Field.required</span></code></a> attribute can be set
to <code class="docutils literal notranslate"><span class="pre">False</span></code> for individual fields to make them optional. If no value
is supplied for a required field, an <code class="docutils literal notranslate"><span class="pre">incomplete</span></code> validation error
will be raised.</p>
<p>A default <code class="docutils literal notranslate"><span class="pre">incomplete</span></code> error message can be defined on the
<a class="reference internal" href="#django.forms.MultiValueField" title="django.forms.MultiValueField"><code class="xref py py-class docutils literal notranslate"><span class="pre">MultiValueField</span></code></a> subclass, or different messages can be defined
on each individual field. For example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.core.validators</span> <span class="k">import</span> <span class="n">RegexValidator</span>

<span class="k">class</span> <span class="nc">PhoneField</span><span class="p">(</span><span class="n">MultiValueField</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="c1"># Define one message for all fields.</span>
        <span class="n">error_messages</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s1">&#39;incomplete&#39;</span><span class="p">:</span> <span class="s1">&#39;Enter a country calling code and a phone number.&#39;</span><span class="p">,</span>
        <span class="p">}</span>
        <span class="c1"># Or define a different message for each field.</span>
        <span class="n">fields</span> <span class="o">=</span> <span class="p">(</span>
            <span class="n">CharField</span><span class="p">(</span>
                <span class="n">error_messages</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;incomplete&#39;</span><span class="p">:</span> <span class="s1">&#39;Enter a country calling code.&#39;</span><span class="p">},</span>
                <span class="n">validators</span><span class="o">=</span><span class="p">[</span>
                    <span class="n">RegexValidator</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;^[0-9]+$&#39;</span><span class="p">,</span> <span class="s1">&#39;Enter a valid country calling code.&#39;</span><span class="p">),</span>
                <span class="p">],</span>
            <span class="p">),</span>
            <span class="n">CharField</span><span class="p">(</span>
                <span class="n">error_messages</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;incomplete&#39;</span><span class="p">:</span> <span class="s1">&#39;Enter a phone number.&#39;</span><span class="p">},</span>
                <span class="n">validators</span><span class="o">=</span><span class="p">[</span><span class="n">RegexValidator</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;^[0-9]+$&#39;</span><span class="p">,</span> <span class="s1">&#39;Enter a valid phone number.&#39;</span><span class="p">)],</span>
            <span class="p">),</span>
            <span class="n">CharField</span><span class="p">(</span>
                <span class="n">validators</span><span class="o">=</span><span class="p">[</span><span class="n">RegexValidator</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;^[0-9]+$&#39;</span><span class="p">,</span> <span class="s1">&#39;Enter a valid extension.&#39;</span><span class="p">)],</span>
                <span class="n">required</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
            <span class="p">),</span>
        <span class="p">)</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">PhoneField</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span>
            <span class="n">error_messages</span><span class="o">=</span><span class="n">error_messages</span><span class="p">,</span> <span class="n">fields</span><span class="o">=</span><span class="n">fields</span><span class="p">,</span>
            <span class="n">require_all_fields</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span>
        <span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.forms.MultiValueField.widget">
<code class="descname">widget</code><a class="headerlink" href="#django.forms.MultiValueField.widget" title="Permalink to this definition">¶</a></dt>
<dd><p>Must be a subclass of <a class="reference internal" href="widgets.html#django.forms.MultiWidget" title="django.forms.MultiWidget"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.forms.MultiWidget</span></code></a>.
Default value is <a class="reference internal" href="widgets.html#django.forms.TextInput" title="django.forms.TextInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextInput</span></code></a>, which
probably is not very useful in this case.</p>
</dd></dl>

<dl class="method">
<dt id="django.forms.MultiValueField.compress">
<code class="descname">compress</code>(<em>data_list</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#MultiValueField.compress"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.MultiValueField.compress" title="Permalink to this definition">¶</a></dt>
<dd><p>Takes a list of valid values and returns  a “compressed” version of
those values – in a single value. For example,
<a class="reference internal" href="#django.forms.SplitDateTimeField" title="django.forms.SplitDateTimeField"><code class="xref py py-class docutils literal notranslate"><span class="pre">SplitDateTimeField</span></code></a> is a subclass which combines a time field
and a date field into a <code class="docutils literal notranslate"><span class="pre">datetime</span></code> object.</p>
<p>This method must be implemented in the subclasses.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-splitdatetimefield">
<span id="splitdatetimefield"></span><h3><code class="docutils literal notranslate"><span class="pre">SplitDateTimeField</span></code><a class="headerlink" href="#splitdatetimefield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.SplitDateTimeField">
<em class="property">class </em><code class="descname">SplitDateTimeField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/fields.html#SplitDateTimeField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.SplitDateTimeField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.SplitDateTimeWidget" title="django.forms.SplitDateTimeWidget"><code class="xref py py-class docutils literal notranslate"><span class="pre">SplitDateTimeWidget</span></code></a></li>
<li>Empty value: <code class="docutils literal notranslate"><span class="pre">None</span></code></li>
<li>Normalizes to: A Python <code class="docutils literal notranslate"><span class="pre">datetime.datetime</span></code> object.</li>
<li>Validates that the given value is a <code class="docutils literal notranslate"><span class="pre">datetime.datetime</span></code> or string
formatted in a particular datetime format.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid_date</span></code>,
<code class="docutils literal notranslate"><span class="pre">invalid_time</span></code></li>
</ul>
<p>Takes two optional arguments:</p>
<dl class="attribute">
<dt id="django.forms.SplitDateTimeField.input_date_formats">
<code class="descname">input_date_formats</code><a class="headerlink" href="#django.forms.SplitDateTimeField.input_date_formats" title="Permalink to this definition">¶</a></dt>
<dd><p>A list of formats used to attempt to convert a string to a valid
<code class="docutils literal notranslate"><span class="pre">datetime.date</span></code> object.</p>
</dd></dl>

<p>If no <code class="docutils literal notranslate"><span class="pre">input_date_formats</span></code> argument is provided, the default input formats
for <a class="reference internal" href="#django.forms.DateField" title="django.forms.DateField"><code class="xref py py-class docutils literal notranslate"><span class="pre">DateField</span></code></a> are used.</p>
<dl class="attribute">
<dt id="django.forms.SplitDateTimeField.input_time_formats">
<code class="descname">input_time_formats</code><a class="headerlink" href="#django.forms.SplitDateTimeField.input_time_formats" title="Permalink to this definition">¶</a></dt>
<dd><p>A list of formats used to attempt to convert a string to a valid
<code class="docutils literal notranslate"><span class="pre">datetime.time</span></code> object.</p>
</dd></dl>

<p>If no <code class="docutils literal notranslate"><span class="pre">input_time_formats</span></code> argument is provided, the default input formats
for <a class="reference internal" href="#django.forms.TimeField" title="django.forms.TimeField"><code class="xref py py-class docutils literal notranslate"><span class="pre">TimeField</span></code></a> are used.</p>
</dd></dl>

</div>
</div>
<div class="section" id="s-fields-which-handle-relationships">
<span id="fields-which-handle-relationships"></span><h2>Fields which handle relationships<a class="headerlink" href="#fields-which-handle-relationships" title="Permalink to this headline">¶</a></h2>
<p>Two fields are available for representing relationships between
models: <a class="reference internal" href="#django.forms.ModelChoiceField" title="django.forms.ModelChoiceField"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModelChoiceField</span></code></a> and
<a class="reference internal" href="#django.forms.ModelMultipleChoiceField" title="django.forms.ModelMultipleChoiceField"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModelMultipleChoiceField</span></code></a>.  Both of these fields require a
single <code class="docutils literal notranslate"><span class="pre">queryset</span></code> parameter that is used to create the choices for
the field.  Upon form validation, these fields will place either one
model object (in the case of <code class="docutils literal notranslate"><span class="pre">ModelChoiceField</span></code>) or multiple model
objects (in the case of <code class="docutils literal notranslate"><span class="pre">ModelMultipleChoiceField</span></code>) into the
<code class="docutils literal notranslate"><span class="pre">cleaned_data</span></code> dictionary of the form.</p>
<p>For more complex uses, you can specify <code class="docutils literal notranslate"><span class="pre">queryset=None</span></code> when declaring the
form field and then populate the <code class="docutils literal notranslate"><span class="pre">queryset</span></code> in the form’s <code class="docutils literal notranslate"><span class="pre">__init__()</span></code>
method:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">FooMultipleChoiceForm</span><span class="p">(</span><span class="n">forms</span><span class="o">.</span><span class="n">Form</span><span class="p">):</span>
    <span class="n">foo_select</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">ModelMultipleChoiceField</span><span class="p">(</span><span class="n">queryset</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">FooMultipleChoiceForm</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="s1">&#39;foo_select&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">queryset</span> <span class="o">=</span> <span class="o">...</span>
</pre></div>
</div>
<div class="section" id="s-modelchoicefield">
<span id="modelchoicefield"></span><h3><code class="docutils literal notranslate"><span class="pre">ModelChoiceField</span></code><a class="headerlink" href="#modelchoicefield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.ModelChoiceField">
<em class="property">class </em><code class="descname">ModelChoiceField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/models.html#ModelChoiceField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.ModelChoiceField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.Select" title="django.forms.Select"><code class="xref py py-class docutils literal notranslate"><span class="pre">Select</span></code></a></li>
<li>Empty value: <code class="docutils literal notranslate"><span class="pre">None</span></code></li>
<li>Normalizes to: A model instance.</li>
<li>Validates that the given id exists in the queryset.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid_choice</span></code></li>
</ul>
<p>Allows the selection of a single model object, suitable for representing a
foreign key. Note that the default widget for <code class="docutils literal notranslate"><span class="pre">ModelChoiceField</span></code> becomes
impractical when the number of entries increases. You should avoid using it
for more than 100 items.</p>
<p>A single argument is required:</p>
<dl class="attribute">
<dt id="django.forms.ModelChoiceField.queryset">
<code class="descname">queryset</code><a class="headerlink" href="#django.forms.ModelChoiceField.queryset" title="Permalink to this definition">¶</a></dt>
<dd><p>A <code class="docutils literal notranslate"><span class="pre">QuerySet</span></code> of model objects from which the choices for the field
are derived and which is used to validate the user’s selection. It’s
evaluated when the form is rendered.</p>
</dd></dl>

<p><code class="docutils literal notranslate"><span class="pre">ModelChoiceField</span></code> also takes two optional arguments:</p>
<dl class="attribute">
<dt id="django.forms.ModelChoiceField.empty_label">
<code class="descname">empty_label</code><a class="headerlink" href="#django.forms.ModelChoiceField.empty_label" title="Permalink to this definition">¶</a></dt>
<dd><p>By default the <code class="docutils literal notranslate"><span class="pre">&lt;select&gt;</span></code> widget used by <code class="docutils literal notranslate"><span class="pre">ModelChoiceField</span></code> will have an
empty choice at the top of the list. You can change the text of this
label (which is <code class="docutils literal notranslate"><span class="pre">&quot;---------&quot;</span></code> by default) with the <code class="docutils literal notranslate"><span class="pre">empty_label</span></code>
attribute, or you can disable the empty label entirely by setting
<code class="docutils literal notranslate"><span class="pre">empty_label</span></code> to <code class="docutils literal notranslate"><span class="pre">None</span></code>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># A custom empty label</span>
<span class="n">field1</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">ModelChoiceField</span><span class="p">(</span><span class="n">queryset</span><span class="o">=...</span><span class="p">,</span> <span class="n">empty_label</span><span class="o">=</span><span class="s2">&quot;(Nothing)&quot;</span><span class="p">)</span>

<span class="c1"># No empty label</span>
<span class="n">field2</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">ModelChoiceField</span><span class="p">(</span><span class="n">queryset</span><span class="o">=...</span><span class="p">,</span> <span class="n">empty_label</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
</pre></div>
</div>
<p>Note that if a <code class="docutils literal notranslate"><span class="pre">ModelChoiceField</span></code> is required and has a default
initial value, no empty choice is created (regardless of the value
of <code class="docutils literal notranslate"><span class="pre">empty_label</span></code>).</p>
</dd></dl>

<dl class="attribute">
<dt id="django.forms.ModelChoiceField.to_field_name">
<code class="descname">to_field_name</code><a class="headerlink" href="#django.forms.ModelChoiceField.to_field_name" title="Permalink to this definition">¶</a></dt>
<dd><p>This optional argument is used to specify the field to use as the value
of the choices in the field’s widget. Be sure it’s a unique field for
the model, otherwise the selected value could match more than one
object. By default it is set to <code class="docutils literal notranslate"><span class="pre">None</span></code>, in which case the primary key
of each object will be used. For example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># No custom to_field_name</span>
<span class="n">field1</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">ModelChoiceField</span><span class="p">(</span><span class="n">queryset</span><span class="o">=...</span><span class="p">)</span>
</pre></div>
</div>
<p>would yield:</p>
<div class="highlight-html notranslate"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">select</span> <span class="na">id</span><span class="o">=</span><span class="s">&quot;id_field1&quot;</span> <span class="na">name</span><span class="o">=</span><span class="s">&quot;field1&quot;</span><span class="p">&gt;</span>
<span class="p">&lt;</span><span class="nt">option</span> <span class="na">value</span><span class="o">=</span><span class="s">&quot;obj1.pk&quot;</span><span class="p">&gt;</span>Object1<span class="p">&lt;/</span><span class="nt">option</span><span class="p">&gt;</span>
<span class="p">&lt;</span><span class="nt">option</span> <span class="na">value</span><span class="o">=</span><span class="s">&quot;obj2.pk&quot;</span><span class="p">&gt;</span>Object2<span class="p">&lt;/</span><span class="nt">option</span><span class="p">&gt;</span>
...
<span class="p">&lt;/</span><span class="nt">select</span><span class="p">&gt;</span>
</pre></div>
</div>
<p>and:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># to_field_name provided</span>
<span class="n">field2</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">ModelChoiceField</span><span class="p">(</span><span class="n">queryset</span><span class="o">=...</span><span class="p">,</span> <span class="n">to_field_name</span><span class="o">=</span><span class="s2">&quot;name&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>would yield:</p>
<div class="highlight-html notranslate"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">select</span> <span class="na">id</span><span class="o">=</span><span class="s">&quot;id_field2&quot;</span> <span class="na">name</span><span class="o">=</span><span class="s">&quot;field2&quot;</span><span class="p">&gt;</span>
<span class="p">&lt;</span><span class="nt">option</span> <span class="na">value</span><span class="o">=</span><span class="s">&quot;obj1.name&quot;</span><span class="p">&gt;</span>Object1<span class="p">&lt;/</span><span class="nt">option</span><span class="p">&gt;</span>
<span class="p">&lt;</span><span class="nt">option</span> <span class="na">value</span><span class="o">=</span><span class="s">&quot;obj2.name&quot;</span><span class="p">&gt;</span>Object2<span class="p">&lt;/</span><span class="nt">option</span><span class="p">&gt;</span>
...
<span class="p">&lt;/</span><span class="nt">select</span><span class="p">&gt;</span>
</pre></div>
</div>
</dd></dl>

<p>The <code class="docutils literal notranslate"><span class="pre">__str__</span></code> (<code class="docutils literal notranslate"><span class="pre">__unicode__</span></code> on Python 2) method of the model will be
called to generate string representations of the objects for use in the
field’s choices; to provide customized representations, subclass
<code class="docutils literal notranslate"><span class="pre">ModelChoiceField</span></code> and override <code class="docutils literal notranslate"><span class="pre">label_from_instance</span></code>. This method will
receive a model object, and should return a string suitable for representing
it. For example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.forms</span> <span class="k">import</span> <span class="n">ModelChoiceField</span>

<span class="k">class</span> <span class="nc">MyModelChoiceField</span><span class="p">(</span><span class="n">ModelChoiceField</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">label_from_instance</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>
        <span class="k">return</span> <span class="s2">&quot;My Object #</span><span class="si">%i</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">obj</span><span class="o">.</span><span class="n">id</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="s-modelmultiplechoicefield">
<span id="modelmultiplechoicefield"></span><h3><code class="docutils literal notranslate"><span class="pre">ModelMultipleChoiceField</span></code><a class="headerlink" href="#modelmultiplechoicefield" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="django.forms.ModelMultipleChoiceField">
<em class="property">class </em><code class="descname">ModelMultipleChoiceField</code>(<em>**kwargs</em>)<a class="reference internal" href="../../_modules/django/forms/models.html#ModelMultipleChoiceField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.forms.ModelMultipleChoiceField" title="Permalink to this definition">¶</a></dt>
<dd><ul class="simple">
<li>Default widget: <a class="reference internal" href="widgets.html#django.forms.SelectMultiple" title="django.forms.SelectMultiple"><code class="xref py py-class docutils literal notranslate"><span class="pre">SelectMultiple</span></code></a></li>
<li>Empty value: An empty <code class="docutils literal notranslate"><span class="pre">QuerySet</span></code> (self.queryset.none())</li>
<li>Normalizes to: A <code class="docutils literal notranslate"><span class="pre">QuerySet</span></code> of model instances.</li>
<li>Validates that every id in the given list of values exists in the
queryset.</li>
<li>Error message keys: <code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">list</span></code>, <code class="docutils literal notranslate"><span class="pre">invalid_choice</span></code>,
<code class="docutils literal notranslate"><span class="pre">invalid_pk_value</span></code></li>
</ul>
<p>The <code class="docutils literal notranslate"><span class="pre">invalid_choice</span></code> message may contain <code class="docutils literal notranslate"><span class="pre">%(value)s</span></code> and the
<code class="docutils literal notranslate"><span class="pre">invalid_pk_value</span></code> message may contain <code class="docutils literal notranslate"><span class="pre">%(pk)s</span></code>, which will be
substituted by the appropriate values.</p>
<p>Allows the selection of one or more model objects, suitable for
representing a many-to-many relation. As with <a class="reference internal" href="#django.forms.ModelChoiceField" title="django.forms.ModelChoiceField"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModelChoiceField</span></code></a>,
you can use <code class="docutils literal notranslate"><span class="pre">label_from_instance</span></code> to customize the object
representations.</p>
<p>A single argument is required:</p>
<dl class="attribute">
<dt id="django.forms.ModelMultipleChoiceField.queryset">
<code class="descname">queryset</code><a class="headerlink" href="#django.forms.ModelMultipleChoiceField.queryset" title="Permalink to this definition">¶</a></dt>
<dd><p>Same as <a class="reference internal" href="#django.forms.ModelChoiceField.queryset" title="django.forms.ModelChoiceField.queryset"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModelChoiceField.queryset</span></code></a>.</p>
</dd></dl>

<p>Takes one optional argument:</p>
<dl class="attribute">
<dt id="django.forms.ModelMultipleChoiceField.to_field_name">
<code class="descname">to_field_name</code><a class="headerlink" href="#django.forms.ModelMultipleChoiceField.to_field_name" title="Permalink to this definition">¶</a></dt>
<dd><p>Same as <a class="reference internal" href="#django.forms.ModelChoiceField.to_field_name" title="django.forms.ModelChoiceField.to_field_name"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModelChoiceField.to_field_name</span></code></a>.</p>
</dd></dl>

</dd></dl>

</div>
</div>
<div class="section" id="s-creating-custom-fields">
<span id="creating-custom-fields"></span><h2>Creating custom fields<a class="headerlink" href="#creating-custom-fields" title="Permalink to this headline">¶</a></h2>
<p>If the built-in <code class="docutils literal notranslate"><span class="pre">Field</span></code> classes don’t meet your needs, you can easily create
custom <code class="docutils literal notranslate"><span class="pre">Field</span></code> classes. To do this, just create a subclass of
<code class="docutils literal notranslate"><span class="pre">django.forms.Field</span></code>. Its only requirements are that it implement a
<code class="docutils literal notranslate"><span class="pre">clean()</span></code> method and that its <code class="docutils literal notranslate"><span class="pre">__init__()</span></code> method accept the core arguments
mentioned above (<code class="docutils literal notranslate"><span class="pre">required</span></code>, <code class="docutils literal notranslate"><span class="pre">label</span></code>, <code class="docutils literal notranslate"><span class="pre">initial</span></code>, <code class="docutils literal notranslate"><span class="pre">widget</span></code>,
<code class="docutils literal notranslate"><span class="pre">help_text</span></code>).</p>
<p>You can also customize how a field will be accessed by overriding
<a class="reference internal" href="api.html#django.forms.Field.get_bound_field" title="django.forms.Field.get_bound_field"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_bound_field()</span></code></a>.</p>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Form fields</a><ul>
<li><a class="reference internal" href="#core-field-arguments">Core field arguments</a><ul>
<li><a class="reference internal" href="#required"><code class="docutils literal notranslate"><span class="pre">required</span></code></a></li>
<li><a class="reference internal" href="#label"><code class="docutils literal notranslate"><span class="pre">label</span></code></a></li>
<li><a class="reference internal" href="#label-suffix"><code class="docutils literal notranslate"><span class="pre">label_suffix</span></code></a></li>
<li><a class="reference internal" href="#initial"><code class="docutils literal notranslate"><span class="pre">initial</span></code></a></li>
<li><a class="reference internal" href="#widget"><code class="docutils literal notranslate"><span class="pre">widget</span></code></a></li>
<li><a class="reference internal" href="#help-text"><code class="docutils literal notranslate"><span class="pre">help_text</span></code></a></li>
<li><a class="reference internal" href="#error-messages"><code class="docutils literal notranslate"><span class="pre">error_messages</span></code></a></li>
<li><a class="reference internal" href="#validators"><code class="docutils literal notranslate"><span class="pre">validators</span></code></a></li>
<li><a class="reference internal" href="#localize"><code class="docutils literal notranslate"><span class="pre">localize</span></code></a></li>
<li><a class="reference internal" href="#disabled"><code class="docutils literal notranslate"><span class="pre">disabled</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#checking-if-the-field-data-has-changed">Checking if the field data has changed</a><ul>
<li><a class="reference internal" href="#has-changed"><code class="docutils literal notranslate"><span class="pre">has_changed()</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#built-in-field-classes">Built-in <code class="docutils literal notranslate"><span class="pre">Field</span></code> classes</a><ul>
<li><a class="reference internal" href="#booleanfield"><code class="docutils literal notranslate"><span class="pre">BooleanField</span></code></a></li>
<li><a class="reference internal" href="#charfield"><code class="docutils literal notranslate"><span class="pre">CharField</span></code></a></li>
<li><a class="reference internal" href="#choicefield"><code class="docutils literal notranslate"><span class="pre">ChoiceField</span></code></a></li>
<li><a class="reference internal" href="#typedchoicefield"><code class="docutils literal notranslate"><span class="pre">TypedChoiceField</span></code></a></li>
<li><a class="reference internal" href="#datefield"><code class="docutils literal notranslate"><span class="pre">DateField</span></code></a></li>
<li><a class="reference internal" href="#datetimefield"><code class="docutils literal notranslate"><span class="pre">DateTimeField</span></code></a></li>
<li><a class="reference internal" href="#decimalfield"><code class="docutils literal notranslate"><span class="pre">DecimalField</span></code></a></li>
<li><a class="reference internal" href="#durationfield"><code class="docutils literal notranslate"><span class="pre">DurationField</span></code></a></li>
<li><a class="reference internal" href="#emailfield"><code class="docutils literal notranslate"><span class="pre">EmailField</span></code></a></li>
<li><a class="reference internal" href="#filefield"><code class="docutils literal notranslate"><span class="pre">FileField</span></code></a></li>
<li><a class="reference internal" href="#filepathfield"><code class="docutils literal notranslate"><span class="pre">FilePathField</span></code></a></li>
<li><a class="reference internal" href="#floatfield"><code class="docutils literal notranslate"><span class="pre">FloatField</span></code></a></li>
<li><a class="reference internal" href="#imagefield"><code class="docutils literal notranslate"><span class="pre">ImageField</span></code></a></li>
<li><a class="reference internal" href="#integerfield"><code class="docutils literal notranslate"><span class="pre">IntegerField</span></code></a></li>
<li><a class="reference internal" href="#genericipaddressfield"><code class="docutils literal notranslate"><span class="pre">GenericIPAddressField</span></code></a></li>
<li><a class="reference internal" href="#multiplechoicefield"><code class="docutils literal notranslate"><span class="pre">MultipleChoiceField</span></code></a></li>
<li><a class="reference internal" href="#typedmultiplechoicefield"><code class="docutils literal notranslate"><span class="pre">TypedMultipleChoiceField</span></code></a></li>
<li><a class="reference internal" href="#nullbooleanfield"><code class="docutils literal notranslate"><span class="pre">NullBooleanField</span></code></a></li>
<li><a class="reference internal" href="#regexfield"><code class="docutils literal notranslate"><span class="pre">RegexField</span></code></a></li>
<li><a class="reference internal" href="#slugfield"><code class="docutils literal notranslate"><span class="pre">SlugField</span></code></a></li>
<li><a class="reference internal" href="#timefield"><code class="docutils literal notranslate"><span class="pre">TimeField</span></code></a></li>
<li><a class="reference internal" href="#urlfield"><code class="docutils literal notranslate"><span class="pre">URLField</span></code></a></li>
<li><a class="reference internal" href="#uuidfield"><code class="docutils literal notranslate"><span class="pre">UUIDField</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#slightly-complex-built-in-field-classes">Slightly complex built-in <code class="docutils literal notranslate"><span class="pre">Field</span></code> classes</a><ul>
<li><a class="reference internal" href="#combofield"><code class="docutils literal notranslate"><span class="pre">ComboField</span></code></a></li>
<li><a class="reference internal" href="#multivaluefield"><code class="docutils literal notranslate"><span class="pre">MultiValueField</span></code></a></li>
<li><a class="reference internal" href="#splitdatetimefield"><code class="docutils literal notranslate"><span class="pre">SplitDateTimeField</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#fields-which-handle-relationships">Fields which handle relationships</a><ul>
<li><a class="reference internal" href="#modelchoicefield"><code class="docutils literal notranslate"><span class="pre">ModelChoiceField</span></code></a></li>
<li><a class="reference internal" href="#modelmultiplechoicefield"><code class="docutils literal notranslate"><span class="pre">ModelMultipleChoiceField</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#creating-custom-fields">Creating custom fields</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="api.html"
                        title="previous chapter">The Forms API</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="models.html"
                        title="next chapter">Model Form Functions</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/ref/forms/fields.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Jun 03, 2019</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="api.html" title="The Forms API">previous</a>
     |
    <a href="../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="models.html" title="Model Form Functions">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>